An if or while tests the literal true or false
What it finds
if (false) { ... } never runs its branch and if (true) always does; while (false) never loops. Such code is usually a leftover from debugging. while (true) is a normal loop and is not reported.
From the rule's source, constant_condition.rs.
fun loop() { if (false) { debug() }tx0 reports: the condition is always false if (true) println("always")tx0 reports: the condition is always true while (false) { work() }tx0 reports: the loop condition is always false while (true) { if (done()) break }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:literal-boolean-condition" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:literal-boolean-condition] reason="..."tx0 explain tx0/kotlin:literal-boolean-condition shows the same in the terminal. Found a false positive? Report it.