Skip to content

Latest commit

 

History

History
143 lines (104 loc) · 1.79 KB

jsx-one-expression-per-line.md

File metadata and controls

143 lines (104 loc) · 1.79 KB

Require one JSX element per line (react/jsx-one-expression-per-line)

🔧 This rule is automatically fixable by the --fix CLI option.

This option limits every line in JSX to one expression each.

Note: The fixer will insert line breaks between any expression that are on the same line.

Rule Details

Examples of incorrect code for this rule:

<App><Hello /></App>

<App><Hello />
</App>

<App>
  <Hello>
  </Hello></App>

<App>
  <Hello /> World
</App>

<App>
  <Hello /> { 'World' }
</App>

<App>
  <Hello /> { this.world() }
</App>

<App>
  { 'Hello' }{ ' ' }{ 'World' }
</App>

<App
  foo
><Hello />
</App>

<App><Hello
  foo
/>
</App>

<App><Hello1 />
     <Hello2 />
     <Hello3 />
</App>

Examples of correct code for this rule:

<App>
  <Hello />
</App>

<App>
  <Hello>
  </Hello>
</App>

<App>
  <Hello />
  World
</App>

<App>
  <Hello />
  { 'World' }
</App>

<App>
  <Hello />
  { this.world() }
</App>

<App>
  { 'Hello' }
  { ' ' }
  { 'World' }
</App>

<App
  foo
>
  <Hello />
</App>

<App>
  <Hello
    foo
  />
</App>

<App>
  <Hello1 />
  <Hello2 />
  <Hello3 />
</App>

Rule Options

...
"react/jsx-one-expression-per-line": [<enabled>, { "allow": "none"|"literal"|"single-child" }]
...

allow

Defaults to none.

Examples of correct code for this rule, when configured as "literal":

<App>Hello</App>

Examples of correct code for this rule, when configured as "single-child":

<App>Hello</App>

<App>{"Hello"}</App>

<App><Hello /></App>

Examples of correct code for this rule, when configured as "non-jsx":

<App>Hello {someVariable}</App>

<App>Hello {<Hello />} there!</App>