a < b < c compares the boolean result of a < b with c

tx0/ts:relational-chaindefaultwarningbug

What it finds

0 < x < 10: comparisons do not chain in JavaScript. The left comparison gives true or false, which the right one compares as 1 or 0, so 0 < x < 10 holds for every x. 0 < x && x < 10 was meant.

Reported are <, <=, > and >= whose left operand, without parentheses, is itself one of them pointing the same way. Mixed chains such as a < b > c and files marked @flow are left alone, since there they are usually type arguments.

From the rule's source, relational_chain.rs.

Example from the rule's tests
function inRange(x: number, a: number, b: number) {  if (0 < x < 10) {tx0 reports: comparisons do not chain; did you mean 0 < x && x < 10?    return true;  }  return a <= x && x <= 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:relational-chain" = "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:relational-chain] reason="..."

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