Skip to content

no-unneeded-ternary

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.

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.

Reported
...
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;
...
js:
lint:
rules:
no-unneeded-ternary: warn # off (default), warn, error

Enabled 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.

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