react/jsx-wrap-multilines
Require parentheses around JSX that spans several lines
Without parentheses, JSX that spans several lines must start on the same line as the return or the =, so its opening tag doesn't line up with its closing tag. If you move it down a line, return followed by a line break returns undefined. With parentheses the JSX can start on its own line.
JSX on one line never needs parentheses.
--fix adds the parentheses, or removes them with "never".
Configure#
Off by default. To turn it on:
[lint.rules]
"react/jsx-wrap-multilines" = "error" # or "warn"Every option, set to its default:
[lint.rules]
"react/jsx-wrap-multilines" = ["error", {
# true, false, "ignore", "parens", "parens-new-line" or "never"
declaration = "parens",
assignment = "parens",
return = "parens",
arrow = "parens",
condition = "ignore",
logical = "ignore",
prop = "ignore",
}]Examples#
function Card({ title }) {
return <section>Missing parentheses around multilines JSX
<h2>{title}</h2>
</section>;
}function Card({ title }) {
return (
<section>
<h2>{title}</h2>
</section>
);
}
const empty = <section />;Options#
Each option is a place where JSX can appear:
| Option | Default | Where |
|---|---|---|
declaration | "parens" | const card = <section> |
assignment | "parens" | card = <section> |
return | "parens" | return <section> |
arrow | "parens" | () => <section> |
condition | "ignore" | The branches of open ? <section> : null |
logical | "ignore" | The right side of &&, || and ?? |
prop | "ignore" | <Page header={<section>} /> |
Each takes one of these values:
| Value | What it does |
|---|---|
"parens" or true | Require parentheses. |
"parens-new-line" | Require parentheses, with ( and ) on different lines from the JSX. |
"never" | Report parentheses around the JSX, even on one line. |
"ignore" or false | Don't check this place. |
{ "declaration": "parens-new-line" }1 problemconst card = (<section>Parentheses around JSX should be on separate lines
<h2>{title}</h2>
</section>);{ "declaration": "parens-new-line" }No problemsconst card = (
<section>
<h2>{title}</h2>
</section>
);{ "logical": "parens" }1 problemconst panel = (
<main>
{open && <section>Missing parentheses around multilines JSX
<h2>{title}</h2>
</section>}
</main>
);{ "return": "never", "declaration": "never" }2 problemsfunction Card({ title }) {
return (
<section>Expected no parentheses around multilines JSX
<h2>{title}</h2>
</section>
);
}
const empty = (<section />Expected no parentheses around multilines JSX);While condition is "ignore", the branches of a conditional that's declared or assigned are checked under declaration or assignment:
const card = open ? <section>Missing parentheses around multilines JSX
<h2>{title}</h2>
</section> : null;When not to use it#
A formatter such as bun fmt or Prettier already adds these parentheses.