no-extra-boolean-cast
What it does
Section titled “What it does”Reports !!x and Boolean(x) in a place that already converts the value to a boolean: the test of if, while, do ... while, for and ?:, the operand of !, and the argument of Boolean(...). const b = !!x, a call argument (f(!!x)) and !!(x) are not reported.
Why it matters
Section titled “Why it matters”The cast changes nothing where the language already tests for truthiness, so it only adds noise and can suggest that the plain value is not allowed there. Where the real boolean is needed (an assignment, an argument), the cast does a job and is left alone.
To fix, remove the !! or the Boolean(...) call.
Example
Section titled “Example”...var x = (a = b) ? 1 : 2, y = a = b ? 1 : 2;if (!!a) {} while (!!a) {} do {} while (!!a); for (; !!a; ) {} var z = !!a ? 1 : 2, w = !!a;if (Boolean(a)) {} if (!Boolean(a)) {} Boolean(!!a); !!!a; if ((!!a)) {} if (a && !!b) {} var u = Boolean(a);Configuration
Section titled “Configuration”js: lint: rules: no-extra-boolean-cast: warn # off (default), warn, errorEnabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line no-extra-boolean-cast 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-extra-boolean-cast |
partial | the enforceForLogicalOperands option is not supported |