no-unused-vars false positive for use on right side of assignment
See original GitHub issueTell us about your environment
- ESLint Version: http://eslint.org/demo
- Node Version: n/a
- npm Version: n/a
What parser (default, Babel-ESLint, etc.) are you using?
Default
Please show your full configuration:
None, inline
What did you do? Please include the actual source code causing the issue.
/* eslint no-unused-vars: "error" */
// 'foo' is defined but never used. (no-unused-vars)
var foo;
foo = 42;
foo = foo();
foo = foo.bar();
foo = bar(foo);
// No error
var bar;
bar = 42;
bar();
What did you expect to happen?
No error. foo
is used multiple times on the right side of the assignment expressions.
What actually happened? Please include the actual, raw output from ESLint.
3:5 - ‘foo’ is defined but never used. (no-unused-vars)
It looks like references are being excluded on both sides of assignment expressions instead of just the left side.
Originally seen on http://stackoverflow.com/questions/39787723/eslint-no-unused-vars-stream-conditional-pipe-use-case
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
typescript-eslint/no-unused-vars false positive in type ...
And we have @typescript-eslint/no-unused-vars error in string with type declaration, which says 'name' is defined but never used.
Read more >no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >babel-plugin-remove-unused-vars - npm
This plugin is NOT perfect. It'll have false-positives and remove used variables or sometimes keep unused variables around.
Read more >babel-plugin-remove-unused-vars - npm package - Snyk
This plugin is NOT perfect. It'll have false-positives and remove used variables or sometimes keep unused variables around. It's highly rare but still...
Read more >Warning Options (Using the GNU Compiler Collection (GCC))
That option can then be used with -Werror= and -Wno-error= as described above. ... flow sensitive warnings, in some cases it may also...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The left side of the final assignment expression is unnecessary, but the variable is “used”, at least according to my interpretation of the rule. You can look at the linked StackOverflow question for a less trivial example. In an ideal world (and I believe this is what you were getting at when you suggested warning on line 7 instead of the declaration), we’d be able to determine statically that the result of the final assignment expression is unused and suggest using the right side by itself. Even supposing that were possible (it may be, and that be really cool), I don’t think that warning should come from no-unused-vars. Put another way, my interpretation of no-unused-vars is that when it declares a variable as unused, I ought to be able to remove that variable from my program without changing the program’s behavior. Does that fit?
Also, welcome to the team! 🎉
@not-an-aardvark I’m open to changing the message that’s reported in order to avoid confusion in those cases. Maybe something like “foo is assigned a value but is never used” instead?
@mysticatea no need to apologize. It’s just that you didn’t leave a comment explaining why you removed “accepted,” so I wasn’t sure if you disagreed that this was a bug, or something else.