AphrodyBun GitHub

Runtime docs · Linter · Rules

react/jsx-one-expression-per-line

Require each child of a JSX element to be on its own line

When tags, text and expressions share a line, it's hard to see how many children an element has, and changing one of them shows up in a diff as a change to all of them. This rule puts every child on its own line, along with the opening and closing tags around it.

--fix adds the line breaks. Where a space between two children matters, it writes {' '} to keep it.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"react/jsx-one-expression-per-line" = "error" # or "warn"

Every option, set to its default. The ones that are commented out are unset by default.

bunfig.toml
[lint.rules]
"react/jsx-one-expression-per-line" = ["error", {
  # allow = <"none", "literal", "single-child" or "non-jsx">,
}]

Examples

Reported:

const greeting = <p>Hello</p>;
const greeting = (
  <p>
    Hello <b>{name}</b>
  </p>
);

Not reported:

const greeting = (
  <p>
    Hello
    {" "}
    <b>
      {name}
    </b>
  </p>
);

Options

allow is the only option:

allowWhat it does
"none" (default)Every child goes on its own line.
"literal"Allow an element on one line if its only child is text.
"single-child"Allow an element on one line if it has only one child, of any kind.
"non-jsx"Allow any layout in an element that has no elements as children.
const greeting = <p>Hello</p>;
const greeting = <p>{message}</p>;
const greeting = <p>{message}</p>;
const wrapped = <p><b /></p>;
const greeting = <p>Hello {name}, you have {count} messages</p>;

When not to use it

A formatter such as bun fmt or Prettier decides where JSX breaks, and it doesn't agree with this rule. Use one or the other.