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: false positive new with member in no-extra-parens (fixes #12740) #13375

Merged
merged 7 commits into from Jul 3, 2020

Conversation

yeonjuan
Copy link
Member

Prerequisites checklist

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

[ ] Documentation update
[x] Bug fix (template)
[ ] 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)

Fixes #12740

I changed it to allow one parens if there is a "CallExpression" node in "MemberExpression" and when it used as a "NewExpression"'s callee.

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

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label May 30, 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 May 30, 2020
@mdjermanovic
Copy link
Member

@yeonjuan I think it might be good to rebase this, #12895 changed this function (and unfortunately some same lines).

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.

This might be a new false negative (one pair of parens is unnecessary):

new ((a()).b).c;

If it isn't easy to fix this, I'd be personally fine with some false negatives in these edge cases, those chains with new are really complicated.

lib/rules/no-extra-parens.js Outdated Show resolved Hide resolved
# Conflicts:
#	lib/rules/no-extra-parens.js
#	tests/lib/rules/no-extra-parens.js
Comment on lines 718 to 725
function isMemberExpInNewCallee(node) {
if (node.type === "MemberExpression") {
return node.parent.type === "NewExpression" && node.parent.callee === node
? true
: isMemberExpInNewCallee(node.parent);
}
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this should go up the tree only if it's object child of another MemberExpression, otherwise this would be a false negative:

"new a[(b()).c]"

Copy link
Member Author

Choose a reason for hiding this comment

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

@mdjermanovic
Thanks! 👍 I added a checking about that and test case.

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!

@kaicataldo kaicataldo merged commit 3f51930 into master Jul 3, 2020
@kaicataldo kaicataldo deleted the issue-12740 branch July 3, 2020 19:43
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 31, 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 Dec 31, 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 false positives with new and member expressions
3 participants