-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule Change: [no-extra-parens] assume unknown node types need to be parenthesised if they are parenthesised #17173
Comments
Considering that |
Makes sense to me 👍 @nzakas what do you think? |
My proposal for the change is essentially this: default:
- return 20;
+ return node.type in eslintVisitorKeys ? 20 : -1; WDYT? |
I think this will make sense for most places where |
Maybe instead parameterise it so the usecases can choose? function getPrecedence(node, useLowestForUnknownNodes = true) {
switch (node.type) {
// ...
default:
return !useLowestForUnknownNodes || node.type in eslintVisitorKeys ? 20 : -1;
}
} |
I think it's simpler and more flexible to always return |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
@nzakas I think your feedback is wanted: #17173 (comment) |
Makes sense to me. 👍 Thanks for the ping @fasttime -- still catching up after missing a couple weeks. |
This change request has been accepted. @bradzacher would you like to submit a PR? |
Sure - I'll look into it! |
What rule do you want to change?
no-extra-parens
What change to do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new default behavior
Example code
What does the rule currently do for this code?
The rule currently errors on this TypeScript code because it doesn't understand that
TSAsExpression
andTSSatisfiesExpression
have a lower precedence thanMemberExpression
.This occurs because the precedence of "unknown" node types is automatically set to the maximum precedence:
eslint/lib/rules/utils/ast-utils.js
Lines 1444 to 1445 in 8bf5505
So whenever the rule compares precedence it assumes the unknown node doesn't need parens
What will the rule do after it's changed?
For existing JS code - no change at all.
For non-JS code (eg TS) that has new AST node types - the rule will assume that these new nodes must be wrapped in parentheses and will not report.
Participation
Additional comments
We do have an extension rule, but some users do use the base rule (either because they choose to or accidentally).
This change would stop annoying false positives which will make users' lives better.
The text was updated successfully, but these errors were encountered: