== or != compares with type conversion
What it finds
a == b converts its operands when their types differ, by rules that are easy to get wrong: '' == 0 and '0' == false are true. === compares without converting.
Comparisons with null, as in x == null, are left alone: they are the common way to test for both null and undefined. The fix to === or !== is safe when both operands have the same type for certain, as for two literals of one type or typeof x and a string, since then the two operators agree; otherwise it is offered as unsafe.
From the rule's source, eqeqeq.rs.
function check(value: unknown, count: number) { if (value == 1) {tx0 reports: use === instead of == return 1; } if (typeof value != "string") {tx0 reports: use !== instead of != return 2; } if (value == null || null != value) { return 3; } return count === 1 || value !== undefined;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:eqeqeq" = "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:eqeqeq] reason="..."tx0 explain tx0/ts:eqeqeq shows the same in the terminal. Found a false positive? Report it.