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
Fix: fix inconsistently works option in no-extra-parens (fixes #12717) #12843
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! Appreciate the additional tests for existing behavior 👍
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, thanks!
It's interesting that the non-optional exception for IIFE doesn't allow parens around IIFE if the function expression has parens: /* eslint no-extra-parens: ["error", "all"] */
((function foo() {return 1;})()) // error This is actually the example from the documentation where it says that the rule always ignores extra parentheses around the immediately-invoked function expressions. But it seems to be intentional: #3667 (comment) So I'm not sure should we change this now, or leave it as is (but fix the example in the documentation). The rule also doesn't allow double parens around IIFE even if the function expression doesn't have parens. |
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, thanks!
It seems that only the built-in IIFE exception doesn't allow multiple parens, but it's better to leave that as is.
The wrong ((function foo() {return 1;})())
example for IIFE can be fixed in PR for #12870.
{ | ||
code: "var a = (b) => ((1 ? 2 : 3))", | ||
output: "var a = (b) => (1 ? 2 : 3)", | ||
options: ["all", { enforceForArrowConditionals: false }], |
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.
This was definitely intentional (#8439 comment). Unfortunately, other options don't work like this, so it's better to align.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix (template) fixes #12717
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Removed
!isParenthesisedTwice(node.body)
for fixing no-extra-parens options work inconsistently #12717.enforceForNewInMemberExpressions : false
) is specified.Added some tests for checks whether they ignore "double extra parens" when the option is specified.
Is there anything you'd like reviewers to focus on?
In my understanding, an arrow function's block statement body can't be parenthesized
()
, because it will change the body's typeBlockStatement
toObjectExpression
.And there is a checking about "double extra parens" when body type is not a
BlockStatement
.So, I think
!isParenthesisedTwice(node.body)
can be removed without another effect.