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:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
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.
@vitorbal Sounds good to me!