react/jsx-indent-props

Enforce consistent indentation of JSX props

fixable

When props are on their own lines, uneven indentation makes them hard to tell apart from the tag and its children. The rule checks each prop that starts a line. The default is 4 spaces more than the line where the tag starts.

--fix corrects the indentation.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"react/jsx-indent-props" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"react/jsx-indent-props" = ["error", {
  indentMode = 4, # "tab", "first" or number
  ignoreTernaryOperator = false,
}]

Examples#

example.jsx2 problems
const field = (
    <Input
      name="email"
            value={email}
    />
);
example.jsxNo problems
const field = (
    <Input
        name="email"
        value={email}
    />
);

Options#

The option is a number of spaces, "tab", "first", or an object:

OptionDefaultWhat it does
indentMode4A number of spaces, "tab" for one tab, or "first" to line up every prop with the first one.
ignoreTernaryOperatorfalseBy default, props of a tag on a line that starts with ? or : get one more level. With true they don't.
bunfig.toml
[lint.rules]
"react/jsx-indent-props" = ["error", 2]
example.jsxwith 2No problems
const field = (
  <Input
    name="email"
    value={email}
  />
);

With "first":

example.jsxwith "first"1 problem
const field = <Input name="email"
  value={email}
/>;
example.jsxwith "first"No problems
const field = <Input name="email"
                     value={email}
/>;

With 2, the props of a tag on a line that starts with ? or : are indented by 4:

example.jsxwith 2No problems
const field = editable
  ? <Input
      name="email"
    />
  : null;
example.jsxwith 21 problem
const field = editable
  ? <Input
    name="email"
  />
  : null;

With ignoreTernaryOperator, they're indented by 2 like any other props:

example.jsxwith { "indentMode": 2, "ignoreTernaryOperator": true }No problems
const field = editable
  ? <Input
    name="email"
  />
  : null;

When not to use it#

If bun fmt or another formatter lays out your code, it already decides the indentation.