! negates the left operand of in or instanceof instead of the test
What it finds
!key in object and !value instanceof Type: ! binds tighter than in and instanceof, so these negate the left operand and test whether true or false is a key or an instance, which is never what is meant.
The fix to !(key in object) changes what the code does to what it says, and is offered as unsafe.
From the rule's source, unsafe_negation.rs.
function check(key: string, object: object, value: unknown) { if (!key in object) {tx0 reports: ! applies to key only; did you mean !(key in object)? return 1; } if (!value instanceof Error) {tx0 reports: did you mean !(value instanceof Error)? return 2; } return !(key in object) || !(value instanceof Error);} 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:unsafe-negation" = "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:unsafe-negation] reason="..."tx0 explain tx0/ts:unsafe-negation shows the same in the terminal. Found a false positive? Report it.