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 false positive with let identifier in for-loop #13981

Merged
merged 1 commit into from Jan 15, 2021

Conversation

mdjermanovic
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:

Tell us about your environment

  • ESLint Version: v7.17.0
  • Node Version: v12.18.4
  • npm Version: v6.14.6

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 2015
  }
};

What did you do? Please include the actual source code causing the issue.

Online Demo

/* eslint no-extra-parens: error */

for ((let)[a].b = 1;;);

What did you expect to happen?

No errors. An expression as ForStatement#init cannot start with let[

IterationStatement in the spec:

for ( [lookahead ≠ let [] Expression[~In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ; Expression[+In, ?Yield, ?Await]opt ) Statement[?Yield, ?Await, ?Return]

If for-loop initializer starts with let[, it can be either a let declaration with an array pattern, or a syntax error.

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

  3:6  error  Unnecessary parentheses around expression  no-extra-parens

autofix:

/* eslint no-extra-parens: error */

for (let[a].b = 1;;);
  3:12  error  Parsing error: Complex binding patterns require an initialization value

What changes did you make? (Give an overview)

Fixed the no-extra-parens rule to not report parens inside a for loop initializer expression if removing those parens would make the expression to start with let[.

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

The similar logic for for-in and for-of loops is slightly wrong, I'll fix that in another PR.

@mdjermanovic mdjermanovic 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 Jan 4, 2021
Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

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

Tests are very thorough, LGTM

@mdjermanovic mdjermanovic merged commit 292b1c0 into master Jan 15, 2021
@mdjermanovic mdjermanovic deleted the noextraparens-forlet branch January 15, 2021 17:33
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 15, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 15, 2021
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.

None yet

2 participants