noUnmodifiedLoopCondition (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noUnmodifiedLoopCondition - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-unmodified-loop-condition
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUnmodifiedLoopCondition": "error" } } }}Description
Section titled “Description”Disallow loop conditions whose variables are never modified in the loop.
A variable in a loop condition usually changes during the loop. If it does not, the loop may never terminate or may not run as intended.
Binary and conditional expressions are checked as a group. The condition is considered modified when any variable in the group changes in the loop. References inside dynamic expressions, such as function calls and property accesses, are ignored because their values may change without a local assignment. A binary or conditional expression containing a dynamic expression is ignored as a group.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”let node = getNode();while (node) { process(node);}code-block.js:2:8 lint/nursery/noUnmodifiedLoopCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This loop condition variable is not modified in the loop.
1 │ let node = getNode();
> 2 │ while (node) {
│ ^^^^
3 │ process(node);
4 │ }
ℹ An unchanged condition can make the loop run forever or prevent it from behaving as intended.
ℹ Update the variable during each iteration, or use a condition whose value can change.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
for (let index = 0; index < 5;) { process(index);}code-block.js:1:21 lint/nursery/noUnmodifiedLoopCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This loop condition variable is not modified in the loop.
> 1 │ for (let index = 0; index < 5;) {
│ ^^^^^
2 │ process(index);
3 │ }
ℹ An unchanged condition can make the loop run forever or prevent it from behaving as intended.
ℹ Update the variable during each iteration, or use a condition whose value can change.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
let node = getNode();while (node) { process(node); node = node.parent;}for (let index = 0; index < items.length; index++) { process(items[index]);}while (object.ready) { process(object);}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.