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
Update: report double extra parens in no-extra-parens (fixes #12127) #12697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! This generally looks good to me, but I'd like to have at least one other person review before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look very good! I'd like to check the whole rule once again.
By the docs, it sounds like any number of extra parens should be allowed when something is excepted by an option.
There are also cases where double parens are indeed required. For example, /*eslint no-cond-assign: "error"*/
var a = ((b = c)) ? foo : bar; // ok
var a = (b = c) ? foo : bar; // not ok So it's probably best to leave that part as is. |
Ooops, But it does check |
Oh. Yes. I got it. The problem has not been discovered because the bug(#12127) allows extra twice parens in those cases. // Error in the current PR
{
code: "var a = ((b = c)) ? foo : bar;",
options: ["all", { conditionalAssign: false }]
} I can fix it, but maybe there are some other undiscovered issues. So can I add more test cases for |
Yes, it seems that this wasn't noticed because of #12127 bug. Now when the bug is going to be fixed, we should ensure that this code stays
That would be great, thanks! |
@mdjermanovic /* eslint no-extra-parens: ["error", "all", { "enforceForArrowConditionals": false }] */
var a = () => (1 ? 2 : 3);
var a = () => ((1 ? 2 : 3)); // Unnecessary parentheses arround expression. The option( By the docs, maybe it is a bug?
|
I agree, fixing that behavior can be a separate PR (if it's a bug at all). It looks like the options are inconsistent about this. Some allow only 1 pair of extra parens while the others allow 1, 2, or more. The documentation isn't very specific about this, although it sounds more like that any number of extra parens should be allowed. It's hard to tell what makes more sense. Probably only 1, except for the special cases such as conditional expressions where the presence of 2 pairs has a meaning for another rule. On the other hand, an option name such as |
It could be nice to change |
@mdjermanovic Yes!. That should be. |
@mdjermanovic It seems to cover all. To note,
Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of notes about **
Maybe we should also fix double parens in MemberExpression(node)
?
Actually, let's do This PR has already a lot of changes, and it seems that the logic in |
@mdjermanovic |
One edge case: |
Just changed the title to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work @yeonjuan, this certainly required a lot of effort. Each line is a separate change and there are so many details.
All cases are covered (MemberExpression
needs a separate PR).
All changes have tests (some refactored functions already had double parens tests) + regression tests where it seemed appropriate.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sticking with this! LGTM.
Thanks for contributing to ESLint! |
…2127) (eslint#12697) * Fix: report double extra parens in no-extra-parens (fixes eslint#12127) * rename function, add comments * review feedback * add more test cases * apply cond-assign-exception to test node only * add more checking for double parens * move unaryExpression and exponentiation check * change comments * rebase checkClass, add test case for regression * add invalid test case * add double parens check for for-of, sequence expression
What is the purpose of this pull request? (put an "X" next to item)
[x] Bug fix (template)
What changes did you make? (Give an overview)
Fix #12127
I tried to solve issue #12127 by adding just
|| hasDoubleExcessParens()
everywhere, but it had a performance issue when checkingArrayExpression
's element nodes.So, I made a new function(
hasExcessParensWithConsiderPrecedence
) which checks extra parens with considering the precedence of a node. This function checksisParenthesisedTwice
only if the node surrounded by at least one extra paren.Is there anything you'd like reviewers to focus on?
This pr doesn't change the option's behavior that @mdjermanovic mentioned.