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

Conversation

@mdjermanovic
Copy link
Member

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?

@mysticatea mysticatea added accepted bug rule and removed triage labels Jun 18, 2019

@mdjermanovic

This comment has been minimized.

Copy link
Member Author

commented Jun 24, 2019

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.

@mysticatea
Copy link
Member

left a comment

LGTM. Thank you very much!

@mysticatea mysticatea merged commit e4c450f into eslint:master Jul 17, 2019

9 checks passed

commit-message PR title follows commit message guidelines
Details
continuous-integration Build #20190624.8 succeeded
Details
continuous-integration (Test on Node.js 10 (Linux)) Test on Node.js 10 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Linux)) Test on Node.js 12 (Linux) succeeded
Details
continuous-integration (Test on Node.js 12 (Windows)) Test on Node.js 12 (Windows) succeeded
Details
continuous-integration (Test on Node.js 12 (macOS)) Test on Node.js 12 (macOS) succeeded
Details
continuous-integration (Test on Node.js 8 (Linux)) Test on Node.js 8 (Linux) succeeded
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.