Skip to content

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

@not-an-aardvark

Description

@not-an-aardvark

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions