Skip to content

no-constant-condition-with-break

Disallow constant conditions, but allow constant true loops that have a real exit path.

This rule reports constant conditions in if statements, ternaries, and loop tests.

It makes one exception for loops such as while (true). Those are allowed when the loop can exit with break, return, or a call you list in loopExitCalls.

Constant false loops are still reported. The loop never runs, so the exit analysis does not matter there.

loopExitCalls is an array of fully qualified call paths that should count as loop exits.

eslint.config.ts
import plugin from "eslint-plugin-cease-nonsense";
export default [
{
plugins: { "cease-nonsense": plugin },
rules: {
"cease-nonsense/no-constant-condition-with-break": [
"error",
{ loopExitCalls: ["coroutine.yield", "task.wait"] },
],
},
},
];
Incorrect
if (true) {
doSomething();
}
const value = true ? a : b;
while (true) {
doSomething();
}
do {
doSomething();
} while (false);
Correct
while (running) {
doSomething();
}
while (true) {
if (shouldStop) break;
doSomething();
}
function run() {
for (; true; ) {
if (done) return;
work();
}
}
while (true) {
coroutine.yield();
work();
}