Both operands of an operator are the same

tx0/ts:identical-operandsdefaultwarningbug

What it finds

a && a, x < x, a ?? a, n - n: an operator applied to the same operand twice gives a fixed or redundant result, which usually means one side was meant to be something else.

The operators are the logical ones, the relational ones, -, /, % and ^. Left out are + and *, which double and square; & and |, since x & x converts to a 32-bit integer; the equality operators, whose use on one operand is the test for NaN that self-comparison covers; and instanceof and in. Operands that call, construct, await, yield, assign or create anything may give different values each time, and operands without names are constants that read as intended. A comparison inside the arguments of expect or of a function whose name starts with assert tests the operator itself.

From the rule's source, identical_operands.rs.

Example from the rule's tests
function check(a: number, b: number, item: { start: number }, items: number[], next: () => number) {  if (item.start < item.start) {tx0 reports: both operands of < are item.start    return 1;  }  const flag = a > 0 || a > 0;tx0 reports: both operands of || are a > 0  const mixed = items[0] - items[0];tx0 reports: both operands of - are items[0]  const index = a + b % b;tx0 reports: both operands of % are b  const ok = a === a || a + a || a * a || (a & a) || (a | a);  const calls = next() < next() || 1 < 1 || a < b;  expect(a <= a).toBe(true);  assert(!(b > b));  return flag && mixed && index && ok && calls;}
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:identical-operands" = "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:identical-operands] reason="..."

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