Skip to content
Permalink
Browse files

Fix: `no-unmodified-loop-condition` false positive (fixes #5166)

  • Loading branch information...
mysticatea committed Feb 6, 2016
1 parent 67e1743 commit 2417bb2526131516e4b02c10ab01432f3fc8d753
Showing with 3 additions and 1 deletion.
  1. +1 −1 lib/rules/no-unmodified-loop-condition.js
  2. +2 −0 tests/lib/rules/no-unmodified-loop-condition.js
@@ -138,7 +138,7 @@ function hasDynamicExpressions(root) {
* @returns {LoopConditionInfo|null} Created loop condition info, or null.
*/
function toLoopCondition(reference) {
if (reference.init || reference.isWrite()) {
if (reference.init) {
return null;
}

@@ -23,6 +23,7 @@ ruleTester.run("no-unmodified-loop-condition", rule, {
"var foo = 0; while (foo++) { }",
"var foo = 0; while (foo = next()) { }",
"var foo = 0; while (ok(foo)) { }",
"var foo = 0, bar = 0; while (++foo < bar) { }",
"var foo = 0, obj = {}; while (foo === obj.bar) { }",
"var foo = 0, f = {}, bar = {}; while (foo === f(bar)) { }",
"var foo = 0, f = {}; while (foo === f()) { }",
@@ -49,6 +50,7 @@ ruleTester.run("no-unmodified-loop-condition", rule, {
{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."]},
{code: "var foo = 0, bar = 0; while (foo && bar) { ++bar; } foo = 1;", errors: ["'foo' is not modified in this loop."]},
{code: "var foo = 0, bar = 0; while (foo && bar) { ++foo; } foo = 1;", errors: ["'bar' is not modified in this loop."]},
{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."]},
{code: "var foo = 0; while (foo ? 1 : 0) { } foo = 1;", errors: ["'foo' is not modified in this loop."]},
{code: "var foo = 0; while (foo) { update(); } function update(foo) { ++foo; }", errors: ["'foo' is not modified in this loop."]},
{code: "var foo; do { } while (foo);", errors: ["'foo' is not modified in this loop."]},

0 comments on commit 2417bb2

Please sign in to comment.
You can’t perform that action at this time.