no-unneeded-ternary
What it does
Section titled “What it does”Reports a conditional expression whose two arms are both boolean literals: a ? true : false (the same as !!a), a ? false : true (!a), and a ? true : true. A conditional with one non-boolean arm is not reported.
Why it matters
Section titled “Why it matters”The condition is already the boolean value, or its negation, so the conditional only restates it in a longer form.
To fix, write the condition (or ! of it); use Boolean(a) where a real boolean is needed from a value that is not one.
Example
Section titled “Example”...function g(a) { if (a) { return 1; } else if (b) { return 2; } }...function i(a) { if (a) { x(); } else { return 2; } }var x = a ? true : false;var y = a ? false : true;var z = a ? b : false;...Configuration
Section titled “Configuration”js: lint: rules: no-unneeded-ternary: warn # off (default), warn, errorEnabled by the presets: js/biome-recommended.
Suppress one line with sudsy-disable-next-line no-unneeded-ternary 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-unneeded-ternary |
partial | the defaultAssignment option is not supported |