| or & combines two boolean conditions where || or && was meant

tx0/ts:bitwise-logicdefaultwarningbug

What it finds

if (a > 0 | b > 0), ok = isValid(x) & isReady: | and & on two boolean operands give 0 or 1 and evaluate both sides, where || and && would give a boolean and stop early. With comparisons on both sides, the bitwise operator is a typo.

Reported are | and & whose two operands are both comparisons, negations or boolean literals. Files marked @flow are left alone: their type arguments, as in useRef<Node | null>(null), read as comparisons. The fix to || or && skips the right side when the left decides, which changes behaviour if it has effects, and is unsafe.

From the rule's source, bitwise_logic.rs.

Example from the rule's tests
function check(a: number, b: number, flags: number) {  if (a > 0 | b > 0) {tx0 reports: | on two conditions; did you mean ||?    return 1;  }  const ok = !a & b === 1;tx0 reports: & on two conditions; did you mean &&?  return ok || (flags & 4) !== 0 || (a | b);}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:bitwise-logic" = "off"

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:bitwise-logic] reason="..."

tx0 explain tx0/ts:bitwise-logic shows the same in the terminal. Found a false positive? Report it.