Exemption for for...of unused variable.
See original GitHub issueIn similar vein to for...in
https://github.com/eslint/eslint/issues/2342
Should there be similar exemption for [async] for...of
?
What rule do you want to change?
no-unused-vars
Does this change cause the rule to produce more or fewer warnings? fewer warnings
How will the change be implemented? (New option, new default behavior, etc.)? I don’t know
Please provide some example code that this change will affect:
async function forever(x) {
for await (const unused of x) {
void unused;
}
}
forever(monitor_network());
What does the rule currently do for this code?
Line 42: 'unused' is defined but never used no-unused-vars
What will the rule do after it’s changed? Nothing
Are you willing to submit a pull request to implement this change? This seems tricky…
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (9 by maintainers)
Top Results From Across the Web
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 >How can I get around declaring an unused variable in a for ...
You can, however, use _ as variable name, which is usually understood as "intentionally unused" (even PyLint etc. knows and respect this).
Read more >Quick fix for unused exception variable removes complete try ...
PY-17901 Automatic fix of "Unused local" removes code with side effects! the complete try statement, instead of just the 'as e' part.
Read more >unused-variable / W0612 - Pylint 2.16.0-dev documentation
Description: Used when a variable is defined but not used. Created by the variables checker.
Read more >Unused function parameters should be removed
Exceptions. When arguments is used in the function body, no parameter is reported as unused. function doSomething(a, b, c) { compute(arguments); }.
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 FreeTop 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
Top GitHub Comments
I’m so sorry for the confusion.
When I read #2342 I was left with the impression that the following is allowed:
But of course that’s only because
unused
could be anything here, e.g. a global, and other rules kick in now:no-undef
,prefer-const
.It didn’t think that the following is semantically different wrt. the unused variable rule and treated both cases the same:
Weirdly there’s test case for the above, as if that’s valid code: https://github.com/eslint/eslint/blob/76fb571a1c15b040e42272435eb0d023cdcb031e/tests/lib/rules/no-unused-vars.js#L159 Yet, if I “enable all rules” in the eslint demo, that very example triggers
no-unused-vars
😕In any case
void unused;
works and keeps eslint silent.Also, as far I can tell
for await (const x of y)
is treated exactly same asfor (const x of y)
.I guess I’m OK then 😃
Note that this issue doesn’t show in the ESLint Demo .
Are you using babel-eslint?