no-constant-condition
What it does
Section titled “What it does”Reports the condition of an if, a ternary or a loop that is a literal (if (true), if (0), x = true ? 1 : 2, while (false)). The usual forms of an endless loop (while (true), while (1), for (;true;), do {} while (true)) are left alone.
Why it matters
Section titled “Why it matters”With a literal as the test one branch always runs and the other never does, so the test is either dead code or a switch that was left on while debugging.
To fix, remove the test and keep the branch that runs, or put the real condition in.
Example
Section titled “Example”...if (true) {} while (0) {} while (true) {} for (;;) {} var c = "x" ? 1 : 2, d = a ? 1 : 2;Configuration
Section titled “Configuration”c: lint: rules: no-constant-condition: warn # off, warn (default), errorcpp: lint: rules: no-constant-condition: warn # off, warn (default), errorcsharp: lint: rules: no-constant-condition: warn # off, warn (default), errorgo: lint: rules: no-constant-condition: warn # off, warn (default), errorjava: lint: rules: no-constant-condition: warn # off, warn (default), errorjs: lint: rules: no-constant-condition: warn # off, warn (default), errorkotlin: lint: rules: no-constant-condition: warn # off, warn (default), errorphp: lint: rules: no-constant-condition: warn # off, warn (default), errorpython: lint: rules: no-constant-condition: warn # off, warn (default), errorruby: lint: rules: no-constant-condition: warn # off, warn (default), errorEnabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line no-constant-condition in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | no-constant-condition |
partial | literals only (no object, function or ! forms) |