Skip to content

Commit 2417bb2

Browse files
committed
Fix: no-unmodified-loop-condition false positive (fixes #5166)
1 parent 67e1743 commit 2417bb2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/rules/no-unmodified-loop-condition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function hasDynamicExpressions(root) {
138138
* @returns {LoopConditionInfo|null} Created loop condition info, or null.
139139
*/
140140
function toLoopCondition(reference) {
141-
if (reference.init || reference.isWrite()) {
141+
if (reference.init) {
142142
return null;
143143
}
144144

tests/lib/rules/no-unmodified-loop-condition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ruleTester.run("no-unmodified-loop-condition", rule, {
2323
"var foo = 0; while (foo++) { }",
2424
"var foo = 0; while (foo = next()) { }",
2525
"var foo = 0; while (ok(foo)) { }",
26+
"var foo = 0, bar = 0; while (++foo < bar) { }",
2627
"var foo = 0, obj = {}; while (foo === obj.bar) { }",
2728
"var foo = 0, f = {}, bar = {}; while (foo === f(bar)) { }",
2829
"var foo = 0, f = {}; while (foo === f()) { }",
@@ -49,6 +50,7 @@ ruleTester.run("no-unmodified-loop-condition", rule, {
4950
{code: "var foo = 0, bar = 9; while (foo < bar) { } foo = 1;", errors: ["'foo' is not modified in this loop.", "'bar' is not modified in this loop."]},
5051
{code: "var foo = 0, bar = 0; while (foo && bar) { ++bar; } foo = 1;", errors: ["'foo' is not modified in this loop."]},
5152
{code: "var foo = 0, bar = 0; while (foo && bar) { ++foo; } foo = 1;", errors: ["'bar' is not modified in this loop."]},
53+
{code: "var a, b, c; while (a < c && b < c) { ++a; } foo = 1;", errors: ["'b' is not modified in this loop.", "'c' is not modified in this loop."]},
5254
{code: "var foo = 0; while (foo ? 1 : 0) { } foo = 1;", errors: ["'foo' is not modified in this loop."]},
5355
{code: "var foo = 0; while (foo) { update(); } function update(foo) { ++foo; }", errors: ["'foo' is not modified in this loop."]},
5456
{code: "var foo; do { } while (foo);", errors: ["'foo' is not modified in this loop."]},

0 commit comments

Comments
 (0)