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

prefer-destructuring reports false positives with compound assignments #7881

Closed
fasttime opened this issue Jan 7, 2017 · 9 comments · Fixed by singapore/lint-condo#215 · May be fixed by iamhunter/teammates#4
Closed

prefer-destructuring reports false positives with compound assignments #7881

fasttime opened this issue Jan 7, 2017 · 9 comments · Fixed by singapore/lint-condo#215 · May be fixed by iamhunter/teammates#4
Assignees
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 patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules

Comments

@fasttime
Copy link
Member

fasttime commented Jan 7, 2017

Tell us about your environment

  • ESLint Version: 3.13.0
  • Node Version: 7.3.0
  • npm Version: 4.0.5

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

default

Please show your full configuration:

{ "parserOptions": { "ecmaVersion": 6 } }

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

/* eslint prefer-destructuring: error */

let foo = 0;
foo += bar.foo;

What did you expect to happen?

No error, I guess.

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

  4:1  error  Use object destructuring                  prefer-destructuring
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jan 7, 2017
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jan 7, 2017
@not-an-aardvark
Copy link
Member

I can reproduce this, thanks for the report.

It's happening because the rule is treating the line the same as

let foo = bar.foo;

...which could be fixed to

let {foo} = bar;

@thealjey
Copy link

thealjey commented Jan 8, 2017

This rule should only test variable definitions, not all types of assignments.
For example, this line is also a false positive:

global.window = jsdom().defaultView;

@not-an-aardvark
Copy link
Member

@thealjey Actually, that looks like it's working as intended -- you can replace that line with

({ defaultView: global.window } = jsdom());

@thealjey
Copy link

thealjey commented Jan 8, 2017

@not-an-aardvark Adding parentheses, seriously?
This rule has a big potential to cleanup the code in variable definitions and function arguments.
But instead you're advising to just overcome its shortcomings, to write longer and harder to read code, simply to make a linting rule pass.
Do you really like what you've written, do you think it's an improvement?

Also, I don't think this rule should complain about things like this:

const {param} = something.property;

because:

  • I might not need a property variable
  • there already is a destructuring assignment

@not-an-aardvark
Copy link
Member

There certainly might be room for improvement in the rule's design -- I was just clarifying that the rule is currently working as intended for your example.

@thealjey
Copy link

thealjey commented Jan 8, 2017

this rule is a very good idea, big 👍 to its author
I would never have come up with something like this myself
it's just that as an average ESLint user I got used to everything always being off the charts awesome
you guys are spoiling us 😃

@kaicataldo
Copy link
Member

@thealjey Feel free to write up a proposal and submit a new issue if you see something you think could be improved.

@thealjey
Copy link

thealjey commented Jan 9, 2017

@kaicataldo
I personally am not that big on helping people :) Creating and properly writing an issue just seems like too much work, sorry 😊

And my suggestion is already out there, it's pretty simple.
It goes like this:

This rule should completely ignore everything but variable definitions (var, const, let, function arguments, commonjs imports) and ignore things that are already a destructuring assignment.

That's it, at least I cannot think of any other valid use for this rule.

@kaicataldo
Copy link
Member

@thealjey Thanks for your input.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules
Projects
None yet
5 participants