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: prefer-destructuring invalid autofix with comma operator #13761

Merged
merged 1 commit into from Oct 23, 2020

Conversation

@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Oct 16, 2020

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.11.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 prefer-destructuring: "error" */

var foo = (a, b).foo;

What did you expect to happen?

1 error and correctly fixed code.

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

1 error, autofixed to:

/* eslint prefer-destructuring: "error" */

var {foo} = a, b;

This declares two variables: foo and b.

What changes did you make? (Give an overview)

Fixed the autofix to add parens depending on the precedence.

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

Copy link
Member

@btmills btmills left a comment

This is subtle; nice catch! LGTM

@btmills btmills merged commit 3175316 into master Oct 23, 2020
12 checks passed
12 checks passed
Verify Files
Details
Test (ubuntu-latest, 14.x)
Details
Test (ubuntu-latest, 13.x)
Details
Test (ubuntu-latest, 12.x)
Details
Test (ubuntu-latest, 10.x)
Details
Test (ubuntu-latest, 10.12.0)
Details
Test (windows-latest, 12.x)
Details
Test (macOS-latest, 12.x)
Details
Browser Test
Details
commit-message Commit message follows guidelines
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details
@btmills btmills deleted the preferdestructuring-comma branch Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.