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: no-extra-parens false positive with functions in default exports #8359

Merged
merged 1 commit into from Mar 31, 2017

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Mar 29, 2017

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

Tell us about your environment

  • ESLint Version: master
  • Node Version: 7.8.0
  • npm Version: 4.2.0

What parser (default, Babel-ESLint, etc.) are you using?

Please show your full configuration:

parserOptions:
  ecmaVersion: 2015
  sourceType: module

rules:
  no-extra-parens: error

What did you do? Please include the actual source code causing the issue.

export default (function() {}).foo;

({}).hasOwnProperty.call(foo, bar);

What did you expect to happen?

No error should be reported, because removing the parentheses would be a syntax error.

What actually happened? Please include the actual, raw output from ESLint.

Errors were reported for both lines.

1:16  error  Gratuitous parentheses around expression  no-extra-parens
2:1  error  Gratuitous parentheses around expression  no-extra-parens

What changes did you make? (Give an overview)

This commit fixes an issue where no-extra-parens would incorrectly report parenthesized functions and classes in export default declarations. Previously, our logic for checking whether a token was allowed at the beginning of an expression (e.g. function to distinguish between function declarations and function expressions) was incomplete, so this commit refactors that logic.

Is there anything you'd like reviewers to focus on?

Nothing in particular

@not-an-aardvark not-an-aardvark 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 labels Mar 29, 2017
@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

I noticed a few related cases where the check still fails, so I'll update this PR in a few minutes.

@eslintbot
Copy link

LGTM

@@ -545,8 +566,6 @@ ruleTester.run("no-extra-parens", rule, {
invalid("bar((function(){}).foo(), 0);", "bar(function(){}.foo(), 0);", "FunctionExpression"),
invalid("bar[(function(){}).foo()];", "bar[function(){}.foo()];", "FunctionExpression"),
invalid("var bar = (function(){}).foo();", "var bar = function(){}.foo();", "FunctionExpression"),
invalid("((function(){}).foo.bar)();", "(function(){}.foo.bar)();", "FunctionExpression", null, { options: ["functions"] }),
invalid("((function(){}).foo)();", "(function(){}.foo)();", "FunctionExpression", null, { options: ["functions"] }),
Copy link
Member Author

Choose a reason for hiding this comment

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

These two cases were moved into "valid" because the functions option is enabled and the parens around the function are necessary (it's the parens around the call expression that are unnecessary). This is consistent with cases like this, where the MemberExpression parens are reported and removed instead of the FunctionExpression parens.

This commit fixes an issue where no-extra-parens would incorrectly report parenthesized functions and classes in `export default` declarations, object literals at the beginning of expression statements.
@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

If people have time, I'd appreciate another review on this -- it has changed significantly since the last review.

@not-an-aardvark not-an-aardvark merged commit e09132f into master Mar 31, 2017
@not-an-aardvark not-an-aardvark deleted the no-extra-parens-export-defaults branch March 31, 2017 19:31
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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.

None yet

4 participants