react/jsx-closing-bracket-location
Enforce where the closing bracket of a multiline JSX tag goes
When a JSX tag's props are spread over several lines, the closing > or /> can end up in several places. This rule keeps it in one. By default the bracket goes on its own line, in the same column as the < that opens the tag.
If the tag has no props, or the tag and its last prop are on one line, the bracket must be on that line too, no matter what the options say.
--fix moves the bracket.
Configure#
Off by default. To turn it on:
[lint.rules]
"react/jsx-closing-bracket-location" = "error" # or "warn"Every option, set to its default:
[lint.rules]
# "after-props", "props-aligned", "tag-aligned" or "line-aligned"
"react/jsx-closing-bracket-location" = ["error", "tag-aligned"]Examples#
const button = (
<Button
label="Save"
onClick={save} /The closing bracket must be aligned with the opening tag (expected column 3 on the next line)>
);const button = (
<Button label="Save"
/The closing bracket must be placed after the last prop>
);
const divider = (
<Divider
/The closing bracket must be placed after the opening tag>
);const button = (
<Button
label="Save"
onClick={save}
/>
);
const small = <Button label="Save" />;Options#
[lint.rules]
"react/jsx-closing-bracket-location" = ["error", "line-aligned"]| Option | Where the bracket goes |
|---|---|
"tag-aligned" (default) | On its own line, in the same column as the opening <. |
"line-aligned" | On its own line, indented like the line that has the opening <. |
"props-aligned" | On its own line, in the same column as the last prop. |
"after-props" | On the same line as the last prop. |
"line-aligned" differs from "tag-aligned" when the tag doesn't start its line:
"line-aligned"No problemsconst button = <Button
label="Save"
onClick={save}
/>;"tag-aligned"1 problemconst button = <Button
label="Save"
onClick={save}
/The closing bracket must be aligned with the opening tag (expected column 16)>;"props-aligned"No problemsconst button = (
<Button
label="Save"
onClick={save}
/>
);"after-props"No problemsconst button = (
<Button
label="Save"
onClick={save} />
);{ "location": "line-aligned" } means the same as "line-aligned". An object can also give each kind of tag its own location:
| Option | Default | What it does |
|---|---|---|
selfClosing | "tag-aligned" | The location for tags that end in />. false turns the check off for them. |
nonEmpty | "tag-aligned" | The location for tags that have a closing tag. false turns the check off for them. |
{ "selfClosing": "after-props", "nonEmpty": "tag-aligned" }No problemsconst form = (
<Form
onSubmit={save}
>
<Button
label="Save" />
</Form>
);When not to use it#
A formatter such as bun fmt or Prettier already decides where the bracket goes.