eslint/no-unmodified-loop-condition Suspicious
它的作用
禁止循环条件中引用那些在循环内部从未被修改的值。
为什么这不好?
依赖于循环体内从不改变的值的循环条件 可能会导致无限循环或逻辑错误。
示例
此规则的错误代码示例:
js
let done = false;
while (!done) {
work();
}此规则的正确代码示例:
js
let done = false;
while (!done) {
done = checkDone();
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-unmodified-loop-condition": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-unmodified-loop-condition": "error",
},
});bash
oxlint --deny no-unmodified-loop-condition版本
此规则在 v1.48.0 中新增。
