eslint: no-unused-vars incorrectly raised when variable is used with for…in
The no-unused-vars error is incorrectly triggered when a variable is only used in a for in
statement.
The following snippet gives the error no-unused-vars
:
(function () {
"use strict";
var key;
for (key in this) return;
})();
3:6 error key is defined but never used no-unused-vars
However, the variable is clearly used in for (key in this)
.
Furthermore, omitting the declaration also results in an error:
(function () {
"use strict";
for (key in this) return;
})();
3:7 error "key" is not defined no-undef
The expected behavior is that the first snippet does not yield any error; the second error is correct.
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 40 (23 by maintainers)
Commits related to this issue
- Docs: Clarify what an unused var is (fixes #2342) — committed to eslint/eslint by nzakas 9 years ago
- Merge pull request #3386 from eslint/issue2342 Docs: Clarify what an unused var is (fixes #2342) — committed to eslint/eslint by nzakas 9 years ago
- Fix: make `no-unused-vars` ignore for...(in | of) loops (fixes #2342) Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...(in | of) loops (fixes #2342) Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...in loops with one return (fixes #2342) Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...in (fixes #2342) Applied only for `for...in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...in (fixes #2342) Applied only for `for...in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...in (fixes #2342) Applied only for `for...in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for...in (fixes #2342) Applied only for `for...in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for-in (fixes #2342) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for-in (fixes #2342) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for-in (fixes #2342) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to markelog/eslint by markelog 8 years ago
- Fix: make `no-unused-vars` ignore for-in (fixes #2342) (#6126) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to eslint/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for-in (fixes #2342) (#6126) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to eslint/eslint by markelog 8 years ago
- Update: make `no-unused-vars` ignore for-in (fixes #2342) (#6126) Applied only for `for-in` loops with only one `return` statement. Also clean jsdocs for internal helpers — committed to eslint/eslint by markelog 8 years ago
Assignment to the variable is not considered usage. So this is not usage:
That’s what the
for-in
loop is doing.Assigning the variable to another variable is usage: