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

Update: no-unused-vars ignores read it modifies itself (fixes #6348) #6535

Merged
merged 3 commits into from
Jun 28, 2016

Conversation

mysticatea
Copy link
Member

Fixes #6348.

no-unused-vars comes to ignore a read of a modification of itself.

  • A read in RHS of an assignment to itself (e.g. a = a + 1)
  • A read in LHS of an assignment (e.g. a += 1)
  • Increments/Decrements (e.g. a++)

Those are ignored only if those exist at the direct child of an
ExpressionStatement node. This is in order to avoid false positive such
foo(a = a + 1)

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @vitorbal, @lo1tuma and @wbecker to be potential reviewers

`no-unused-vars` comes to ignore a read of a modification of itself.

- A read in RHS of an assignment to itself (e.g. `a = a + 1`)
- A read in LHS of an assignment (e.g. `a += 1`)
- Increments/Decrements (e.g. `a++`)

Those are ignored only if those exist at the direct child of an
ExpressionStatement node. This is in order to avoid false positive such
`foo(a = a + 1)`
@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member Author

2nd commit is removing 2 unused variables in our repo. Those were found newly by this fix. 😉

@ilyavolodin
Copy link
Member

Nice, LGTM

{code: "var a = 0, b; b = a++; foo(b);"},
{code: "function foo(a) { var b = a = a + 1; bar(b) } foo();"},
{code: "function foo(a) { var b = a += a + 1; bar(b) } foo();"},
{code: "function foo(a) { var b = a++; bar(b) } foo();"}
Copy link
Member

Choose a reason for hiding this comment

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

Can we have test cases for something like:

var a = 2;
a = a * 5 + 6;

Should this pass?

Also,

var a = 2, b = 4;
a = a * 2 + b; // b should count as used here

If these tests exist already, my apologies, I only read the diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!
I added suggested tests.

@eslintbot
Copy link

LGTM

@nzakas nzakas merged commit 1290657 into master Jun 28, 2016
@mysticatea mysticatea deleted the issue6348 branch July 9, 2016 08:43
@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
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants