no-constant-condition-with-break
Disallow constant conditions, but allow constant true loops that have a real exit path.
Rule details Problem
Section titled “Rule details ”ProblemThis 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.
Options
Section titled “Options”loopExitCalls is an array of fully qualified call paths that should count as loop exits.
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"] }, ], }, },];Examples
Section titled “Examples” 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();}Related rules
Section titled “Related rules” ESLint no-constant-condition The built-in rule. This rule is stricter about constant conditions, but looser for intentional infinite loops with exits.