A value is compared with NaN, which equals nothing
What it finds
x === NaN: NaN is not equal to anything, itself included, so a comparison with it is always false, or true for !==, and a case NaN never matches.
NaN counts when it is the global one, as NaN, Number.NaN or globalThis.NaN. The fix to Number.isNaN(x) does what was meant but changes what the code does, so it is offered as unsafe.
From the rule's source, nan_equality_test.rs.
function check(value: number) { if (value === NaN) {tx0 reports: comparing with NaN is always false return 1; } if (Number.NaN !== value) {tx0 reports: comparing with Number.NaN is always true return 2; } switch (value) { case NaN:tx0 reports: case NaN never matches return 3; } return Number.isNaN(value) || value < globalThis.NaN;tx0 reports: comparing with globalThis.NaN is always false} function shadowed(NaN: number, value: number) { return value === NaN;} 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:
[rules]
"tx0/ts:nan-equality-test" = "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:nan-equality-test] reason="..."tx0 explain tx0/ts:nan-equality-test shows the same in the terminal. Found a false positive? Report it.