-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
LGTM |
`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)`
LGTM |
2nd commit is removing 2 unused variables in our repo. Those were found newly by this fix. 😉 |
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();"} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
LGTM |
Fixes #6348.
no-unused-vars
comes to ignore a read of a modification of itself.a = a + 1
)a += 1
)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)