boolean-literal-comparison
What it does
Section titled “What it does”Reports an equality or inequality with a boolean literal on either side (x == true, x !== false, true == x, x != False). The option literals lists the texts that count as boolean literals, not_operators the operators that are not a comparison of value (Python is). Off by default.
Why it matters
Section titled “Why it matters”Comparing a condition with true or false adds a token pair that says what the expression already says. x == true reads longer than x, and for values that are not strictly boolean (a number, a string) the comparison also means something other than the plain test.
To fix, use the expression itself, or ! before it.
Example
Section titled “Example”x = 1x == Truex != FalseTrue == xx is Truex == 1Configuration
Section titled “Configuration”c: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []cpp: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []csharp: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []java: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []js: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []kotlin: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []php: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []python: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []ruby: lint: rules: boolean-literal-comparison: level: warn # off (default), warn, error options: literals: ["true","false","True","False"] not_operators: []| Option | Type | Default | Description |
|---|---|---|---|
literals |
list | ["true","false","True","False"] |
The texts that are boolean literals |
not_operators |
list | [] |
Equality operators that are not a comparison of value (Python is) |
Suppress one line with sudsy-disable-next-line boolean-literal-comparison 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 |
|---|---|---|---|
| checkstyle | SimplifyBooleanExpression |
partial | Only a comparison with a boolean literal, not the double negation or the conditional forms. |
| ruff | E712 |
full |