An if gives true in one branch and false in the other
What it finds
if (ready) true else false is ready, and if (ready) false else true is !ready. The condition is already the Boolean wanted.
From the rule's source, boolean_literal_branches.rs.
fun flags(ready: Boolean, count: Int): Boolean { val a = if (ready) true else falsetx0 reports: the if gives its condition val b = if (count > 0) { false } else { true }tx0 reports: the if gives the negation of its condition val c = if (ready) true else count > 0 return a && b && c} 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:if-yields-boolean-literals" = "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:if-yields-boolean-literals] reason="..."tx0 explain tx0/kotlin:if-yields-boolean-literals shows the same in the terminal. Found a false positive? Report it.