An expression chains more &&, || and ?? operators than the configured maximum

tx0/ts:logical-operator-countrecommendedwarningmaintainability

What it finds

A long chain of &&, || and ?? packs many conditions into one expression, and mixing them makes it easy to misread which operands belong together. Naming parts of it with variables or a function makes the intent visible.

The operators are counted over the whole chain, through parentheses, so (a && b) || (c && d) has three. Operators inside a call argument, a function or any other operand start a chain of their own. The chain is reported once, where it starts. The limit is the parameter max (4 by default).

From the rule's source, logical_operator_count.rs.

Example from the rule's tests
function check(a: boolean, b: boolean, c: boolean, d: boolean, e: boolean, f: boolean) {  if (a && b && c && d && e) {    return 1;  }  if ((a || b) && (c || d) && (e || f)) {tx0 reports: this expression has 5 logical operators, more than 4    return 2;  }  return call(a && b && c, d || e || f) ?? 0;}declare function call(x: boolean, y: boolean): number | null;
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:logical-operator-count" = "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/ts:logical-operator-count] reason="..."

tx0 explain tx0/ts:logical-operator-count shows the same in the terminal. Found a false positive? Report it.