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.

Proposal: Add exception option to `no-extra-parens` to allow parens around React components

See original GitHub issue

The rule no-extra-parens currently flags parens around React components spanning multiple lines:

const component = (
  <div>
    <h1>Hello world</h1>
  </div>
)

However, some believe that wrapping multiline React components is the preferred way to write them to increase readability.

Proposal

Introduce a new exception option to this rule, reactComponents (or just react for brevity) which, when set to false, would not flag React components wrapped in parens as issues.

ESLint: 3.7.1 Parser: babel-eslint no-extra-parens configuration:

{ 'no-extra-parens': [1, 'all', {
    nestedBinaryExpressions: false
  }]
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Oct 19, 2016

I think I can get behind JSX options (including multi-line vs single-line). JSX can at least be represented as a syntactical construct, rather than being React-specific.

Can someone draft a proposal (see Rule Change guidelines) and ping me when that’s done so I can try to get the team to review?

1reaction
ljharbcommented, Oct 13, 2016

This would be great, as it’s blocking Airbnb’s config from enabling no-extra-parens - precisely because our guide requires that multiline JSX be paren-wrapped.

However, it also allows single-line JSX to be paren-wrapped, which means multiline wouldn’t suffice for our use case (@platinumazure)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Add JSX-specific overrides to no-extra-parens #7444
The default setting will be to treat parens around JSX components just ... Proposal: Add exception option to no-extra-parens to allow parens ......
Read more >
Error Boundaries - React
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI ......
Read more >
Error Handling in React 16 – React Blog
As React 16 release is getting closer, we would like to announce a few changes to how React handles JavaScript errors inside components....
Read more >
Passing Functions to Components - React
Pass event handlers and other functions as props to child components: ... You can use an arrow function to wrap around an event...
Read more >
Rules of Hooks - React
Don't call Hooks from regular JavaScript functions. Instead, you can: ✓ Call Hooks from React function components. ✓ Call Hooks from custom Hooks...
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