no-unmodified-loop-condition
Added in v0.4.2Configuration
Rule Details
Disallows variables in loop conditions that are not modified by the loop. A modification may occur while evaluating the condition, in the loop body, or in a for loop's increment expression. If a variable used in a loop's test condition is never assigned to, incremented, or decremented in any of those places, it is likely a bug that leads to an infinite loop or incorrect termination.
References nested inside function calls, member access expressions, new expressions, or yield expressions are skipped, since those may have side effects that modify the condition indirectly. Binary expression groups, and by default ternary expression groups, are also skipped when they contain one of those dynamic expressions or a tagged template.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule accepts an object option with checkConditionalExpressions, which defaults to false.
When checkConditionalExpressions is true, references in the test and branches of a ternary expression are checked independently instead of treating the whole ternary as one group. For example, this reports done because only chunk is modified: