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 autofix with in in a for-loop init (fixes #11706) #11848

Merged
merged 2 commits into from Jul 17, 2019
Merged

Fix: no-extra-parens autofix with in in a for-loop init (fixes #11706) #11848

merged 2 commits into from Jul 17, 2019

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Jun 16, 2019

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

[x] Bug fix: #11706

What changes did you make? (Give an overview)

In the no-extra-parens rule, keep parens if necessary when an in expression is in a for-loop initializer.

For example, the following will be treated as a correct code (not reported):

for (let a = (b in c); ;);

for (let a = (b in c && d); ;);

for (let a = b => (b in c); ;);

Removing parens would produce SyntaxError. Each line would be treated as an invalid for-in loop.

Also, this change is trying to minimize false negatives, i.e. to remove really 'extra' parens.

For example, the following:

for (let a = ((b in c) && (d in e)); ;);

would be fixed to:

for (let a = (b in c && d in e); ;);

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 Jun 16, 2019
@mysticatea mysticatea 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 Jun 18, 2019
@mdjermanovic
Copy link
Member Author

The following is done in this commit:

  • The loop now checks {}, [] etc. by the provided list.
  • The logic for twice parenthesized nodes is added.
  • The old loop was missing cases like (!(b in c)) - necessary parens inside the unnecessary ones. This is fixed now.
  • A small refactoring to support more cases like this, if they occur.

While doing this I've also found two possible bugs (missing checks) on master, I'll open the issues.

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you very much!

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 produces invalid autofix with an in expression in a for-loop initializer
2 participants