A value is compared with true or false

tx0/go:bool-literal-comparisonstrictwarningstyle

What it finds

ok == true, done != false: comparing with a boolean literal says the same as the value itself or its negation, in more words.

This rule is in the strict tier because without types it cannot tell a bool from an interface holding one, where v == true is the right test. The fix is safe when the operand is a comparison or a logical expression, which is always a bool; otherwise it is offered as unsafe.

From the rule's source, bool_literal_comparison.rs.

Example from the rule's tests
package p func f(ok bool, n int, v any) bool {	if ok == true {tx0 reports: the comparison with true can be left out	}	if false != ok {tx0 reports: the comparison with false can be left out	}	if ok == false {tx0 reports: the comparison with false can be written as a negation	}	if (n > 0) != true {tx0 reports: the comparison with true can be written as a negation	}	if true == false {	}	if v == true {tx0 reports: the comparison with true can be left out	}	return ok}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:bool-literal-comparison" = "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/go:bool-literal-comparison] reason="..."

tx0 explain tx0/go:bool-literal-comparison shows the same in the terminal. Found a false positive? Report it.