!a === b negates the left operand instead of the comparison

tx0/ts:negated-equality-operandrecommendedwarningbug

What it finds

!status === "done": ! binds tighter than ===, so this compares the boolean !status with a string, which is never equal. status !== "done" was meant.

Reported are ==, ===, != and !== whose left operand is a single ! applied to something, and whose right operand is not a boolean literal, a comparison or another negation, with which comparing a negated value can make sense. The fix to !(a === b) changes what the code does, so it is unsafe.

From the rule's source, negated_equality_operand.rs.

Example from the rule's tests
function check(status: string, ready: boolean, other: boolean) {  if (!status === "done") {tx0 reports: ! applies to status only; did you mean `!(status ===     return 1;  }  const a = !ready === other;tx0 reports: ! applies to ready only  return a || !ready === false || !ready === !other;}
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:negated-equality-operand" = "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:negated-equality-operand] reason="..."

tx0 explain tx0/ts:negated-equality-operand shows the same in the terminal. Found a false positive? Report it.