no-unmodified-loop-condition
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-unmodified-loop-condition": "error",
},
},
];let node = something;
while (node) {
doSomething(node);
}
node = other;
for (let j = 0; j < 5;) {
doSomething(j);
}
while (node !== root) {
doSomething(node);
}while (node) {
doSomething(node);
node = node.parent;
}
for (let j = 0; j < items.length; ++j) {
doSomething(items[j]);
}
// OK, the result of this binary expression is changed in this loop.
while (node !== root) {
doSomething(node);
node = node.parent;
}
// OK, the result of this ternary expression is changed in this loop.
while (node ? A : B) {
doSomething(node);
node = node.parent;
}
// A property might be a getter which has side effect...
// Or "doSomething" can modify "obj.foo".
while (obj.foo) {
doSomething(obj);
}
// A function call can return various values.
while (check(obj)) {
doSomething(obj);
}Examples from the ESLint documentation.
no-unmodified-loop-condition
eslint
export default [
{
rules: {
"no-unmodified-loop-condition": "error",
},
},
];no-unmodified-loop-condition
eslint plugin · suspicious
{
"rules": {
"no-unmodified-loop-condition": "error"
}
}nursery/noUnmodifiedLoopCondition
nursery · since 2.5.12
{
"linter": {
"rules": {
"nursery": {
"noUnmodifiedLoopCondition": "error"
}
}
}
}Enforce getter and setter pairs in objects and classes
Require return statements to either always or never specify values
Disallow dangling underscores in identifiers