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

no-extra-parens produces invalid autofix with an in expression in a for-loop initializer #11706

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

Comments

@not-an-aardvark
Copy link
Member

Tell us about your environment

  • ESLint Version: master
  • Node Version: 12.1.0
  • npm Version: 6.9.0

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

default

Please show your full configuration:

Configuration
rules:
  no-extra-parens: error

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

for (let a = (b in c); ;);
eslint --fix

What did you expect to happen?

I expected ESLint to not produce an error because removing the parentheses would cause a syntax error.

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

ESLint produced the following invalid autofix:

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

This is interpreted as an initializer in a for-in loop, which is a syntax error in most cases (and is not the intended semantics of the code).

Demo

This issue was detected by running the fuzzer locally.

Are you willing to submit a pull request to fix this bug?

Yes, but not sure when I'll have time.

@not-an-aardvark not-an-aardvark added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels May 10, 2019
@mdjermanovic
Copy link
Member

Similar bugs, but with parentheses around parent nodes:

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

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

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

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

Question: Disable just autofix or the whole warning? These seem to be necessary parentheses, not 'extra'.

@not-an-aardvark
Copy link
Member Author

I suppose the whole warning should be disabled in this case -- as you said, the parentheses are necessary.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jan 14, 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 Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.