question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsx-one-expression-per-line should ignore inline elements

See original GitHub issue

It doesn’t seem to make sense to one-line inline elements.

For example, one-lining the em element in the example below doesn’t make sense.

<Styled.PasswordInstructions errored={ !!formErrors.userPassword }>
  Passwords must be at least 8 characters long and can&apos;t be
  things like <em>password</em>, <em>123456</em> or <em>abcdef</em>.
</Styled.PasswordInstructions>

Here is the “fixed” version.

<Styled.PasswordInstructions errored={ !!formErrors.userPassword }>
  Passwords must be at least 8 characters long and can&apos;t be
  things like
  <em>
    password
  </em>
  ,
  <em>
    123456
  </em>
  or
  <em>
    abcdef
  </em>
  .
</Styled.PasswordInstructions>

I could also see an option allowing the developer to choose which elements to ignore along with an ignoreInline option.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:50
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

27reactions
MrHencommented, Jul 31, 2018

I recently had to disable react/jsx-one-expression-per-line because it made things like this much harder to read:

        <div>
            <span>ABC</span>
            { one && <span>DEF</span> }
            <span>GHI {two} JKL</span>
        </div>

Result:

        <div>
            <span>
                ABC
            </span>
            { one &&
                <span>
                    DEF
                </span>
            }
            <span>
                GHI
                {' '}
                {two}
                {' '}
                JKL
            </span>
        </div>

What I want to prevent is someone trying to inline nested tags. I don’t care about people using <span>ABC</span> – that’s easy enough to read. I can understand why the lint rule current does what it does but it would be handy to have an option to ignore inlined non-tag expressions.

8reactions
ljharbcommented, Jun 27, 2018

See #1855; I think they’re related.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsx-one-expression-per-line should ignore inline elements
It doesn't seem to make sense to one-line inline elements. For example, one-lining the em element in the example below doesn't make sense....
Read more >
Eslint react/jsx-one-expression-per-line: allow variables and ...
javascript - Eslint react/jsx-one-expression-per-line: allow variables and JSX strings on the same line, but not elements - Stack Overflow. ...
Read more >
Conditional Rendering - React
Use JavaScript operators like if or the conditional operator to create elements representing the current state, and let React update the UI to...
Read more >
node_modules/eslint-plugin-react ... - GitLab
If you installed ESLint globally, you have to install React plugin globally too. ... react/jsx-one-expression-per-line: Limit to one expression per line in ...
Read more >
React, Part I: JSX Cheatsheet - Codecademy
A JSX expression that spans multiple lines must be wrapped in parentheses: ( and ) . In the example code, we see the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found