A comparison or type check is a statement of its own, and its result is dropped
What it finds
a == b on a line of its own computes a Boolean and drops it. It is usually an assignment written with ==, or an assertion that lost its check or assert.
From the rule's source, discarded_comparison.rs.
fun update(a: Int, b: Int, items: List<Int>): Boolean { var total = a total == btx0 reports: the result of total == b is not used a is Inttx0 reports: the result of a is Int is not used if (a > 1) { a < btx0 reports: the result of a < b is not used } val ok = items.any { it == a } return total == b} 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:comparison-result-unused" = "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:comparison-result-unused] reason="..."tx0 explain tx0/kotlin:comparison-result-unused shows the same in the terminal. Found a false positive? Report it.