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
Conversation
LGTM |
I noticed a few related cases where the check still fails, so I'll update this PR in a few minutes. |
18aef8b
to
a9a8102
Compare
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"] }), |
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 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.
a9a8102
to
8147765
Compare
LGTM |
If people have time, I'd appreciate another review on this -- it has changed significantly since the last review. |
What is the purpose of this pull request? (put an "X" next to item)
[x] Bug fix
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
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.
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