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.

No way to enable "no-extra-parens" on JSX and functions only

See original GitHub issue
  • ESLint Version: 3.16.1
  • Node Version: 6.9.5
  • npm Version: 3.10.10

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

"no-extra-parens": ["error", "all", {
  "conditionalAssign": false,
  "returnAssign": false,
  "nestedBinaryExpressions": false,
  "ignoreJSX": "multi-line"
 }]

What did you do? Please include the actual source code causing the issue.

fn(x, (y ? 25 : 42))

What did you expect to happen?

No error.

What actually happened? Please include the actual, raw output from ESLint.

Gratuitous parentheses around expression. (no-extra-parens)

Backstory:

We were using the no-extra-parens rule with the "functions" option. But we wanted to also enforce that single-line JSX expressions don’t have needless parens. It seemed that changing the rule from:

"no-extra-parens": ["error", "functions"]

To this:

"no-extra-parens": ["error", "all", {
  "conditionalAssign": false,
  "returnAssign": false,
  "nestedBinaryExpressions": false,
  "ignoreJSX": "multi-line"
 }]

Should have done the trick. But apparently "all" includes some checks for extra parens around expressions, but does not offer a way to disable those checks like with the other options (conditionalAssign, returnAssign, nestedBinaryExpressions, etc.)

We only want to prevent single-line JSX and functions from having extra parens, i.e. these two cases:

const z = (<h1>hey</h1>)
((function foo() {}))()

Is it reasonable to allow users to disable these other checks with the second object parameter?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vitorbalcommented, Mar 9, 2017

If something like a "callExpressionArguments" option is enough to satisfy the use-case for standard, I’d say we can treat this as an enhancement to add just that option.

We can worry about more options in the future, if the need ever comes.

1reaction
ferosscommented, Apr 4, 2017

@vitorbal Sounds good to me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-extra-parens - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
JSX In Depth - React
Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, ...children) function. The JSX code:.
Read more >
Why shouldn't JSX props use arrow functions or bind?
Using arrow functions or binding in JSX is a bad practice that hurts performance, because the function is recreated on each render. Whenever...
Read more >
React | IntelliJ IDEA Documentation - JetBrains
Javascript and TypeScript , JavaScript Debugger - The plugins are available only in IntelliJ IDEA Ultimate, where they are enabled by ...
Read more >
How to use Props in React - Robin Wieruch
As you may have noticed, props are only passed from top to bottom in React application's component hierarchy. There is no way to...
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