react/jsx-newline
Require or disallow an empty line between JSX elements and expressions
fixable
Empty lines between siblings break up a long JSX tree. Some teams want them everywhere, and others want them nowhere. By default the rule requires an empty line before each element or {...} expression that follows another one.
--fix adds or removes the empty line.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"react/jsx-newline" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"react/jsx-newline" = ["error", {
prevent = false,
allowMultilines = false,
}]Examples#
example.jsx2 problems
const page = (
<main>
<Header />
<Content />JSX element should start in a new line
{footer}JSX element should start in a new line
</main>
);example.jsxNo problems
const page = (
<main>
<Header />
<Content />
{footer}
</main>
);Options#
| Option | Default | What it does |
|---|---|---|
prevent | false | Report the empty lines instead of requiring them. |
allowMultilines | false | Only works together with prevent. Still require an empty line before and after an element that takes several lines. |
With prevent:
example.jsxwith
{ "prevent": true }1 problemconst page = (
<main>
<Header />
<Content />JSX element should not start in a new line
</main>
);example.jsxwith
{ "prevent": true }No problemsconst page = (
<main>
<Header />
<Content />
</main>
);With prevent and allowMultilines:
example.jsxwith
{ "prevent": true, "allowMultilines": true }No problemsconst page = (
<main>
<Header />
<Nav />
<Content>
<Article />
</Content>
<Footer />
</main>
);example.jsxwith
{ "prevent": true, "allowMultilines": true }1 problemconst page = (
<main>
<Header />
<Content>Multiline JSX elements should start in a new line
<Article />
</Content>
</main>
);