Skip to content

boolean-literal-comparison

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.

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.

Reported
x = 1
x == True
x != False
True == x
x is True
x == 1
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.

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