A boolean expression chains more && and || operators than the configured maximum

tx0/go:complex-conditionstrictwarningmaintainability

What it finds

if a && b || c && !d || e && f: a long chain of conditions is hard to read correctly, especially when && and || mix, and a mistake in it shows only for some inputs. Naming the parts, as variables or small functions, says what each one means.

The operators are counted in the largest expression made only of &&, || and parentheses around such expressions; an expression inside a call or a function literal is counted on its own. The maximum is the parameter max_operators, 4 by default.

From the rule's source, complex_condition.rs.

Example from the rule's tests
package p func f(a, b, c, d, e, g bool) bool {	if a && b || c && !d || e && g {tx0 reports: this condition chains 5 && and || operators, more than 4		return true	}	return a && (b || c) && d}
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:complex-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/go:complex-condition] reason="..."

tx0 explain tx0/go:complex-condition shows the same in the terminal. Found a false positive? Report it.