question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exemption for for...of unused variable.

See original GitHub issue

In 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dimaqqcommented, Sep 30, 2019

I’m so sorry for the confusion.

When I read #2342 I was left with the impression that the following is allowed:

for (unused in something) {}

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:

for (const unused in something) {}

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 as for (const x of y).

I guess I’m OK then 😃

1reaction
kaicataldocommented, Sep 26, 2019

Note that this issue doesn’t show in the ESLint Demo .

Are you using babel-eslint?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found