Skip to content
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

Merged
merged 1 commit into from Feb 14, 2020

Conversation

yeonjuan
Copy link
Member

@yeonjuan yeonjuan commented Jan 29, 2020

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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)

  1. Removed !isParenthesisedTwice(node.body) for fixing no-extra-parens options work inconsistently #12717.

    • It will make this rule to ignore checking "double extra parens" if the option (enforceForNewInMemberExpressions : false) is specified.
  2. Added some tests for checks whether they ignore "double extra parens" when the option is specified.

    • Other options which not added test in this PR already have test cases ensuring it.
    • returnAssign, nestedBinaryExpressions, enforceForSequenceExpressions, enforceForNewInMemberExpressions.

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 type BlockStatement to ObjectExpression.

var a = () => {  }; // BlockStatement
var a = () => ({ }); // ObjectExpression

And there is a checking about "double extra parens" when body type is not a BlockStatement.

if (node.body.type !== "BlockStatement") {
   // ...
    if (hasExcessParensWithPrecedence()) { 
 
   }
   // ...

So, I think !isParenthesisedTwice(node.body) can be removed without another effect.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Jan 29, 2020
@yeonjuan yeonjuan added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jan 29, 2020
Copy link
Member

@kaicataldo kaicataldo left a 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 👍

tests/lib/rules/no-extra-parens.js Show resolved Hide resolved
Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic
Copy link
Member

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.

Copy link
Member

@mdjermanovic mdjermanovic left a 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 }],
Copy link
Member

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.

@btmills btmills merged commit 1f1424c into master Feb 14, 2020
@btmills btmills deleted the issue12717 branch February 14, 2020 15:57
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 14, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no-extra-parens options work inconsistently
4 participants