Dont-Negate-Is-Instanceof-Operands¶
Sourcery rule id: dont-negate-is-instanceof-operands
¶
Description¶
in
and instanceof
have lower precedence than negation operators.
Match¶
if (!"prop" in myObj) { // Noncompliant; "in" operator is checking property "false"
doTheThing(); // this block will be never executed
}
Explanation¶
Since negation is applied first, checking !key in dict
checks whether !key
is in dict
rather than whether the key
is not in the dict
, and similarly with instanceof
.
This rule warns when the left operand of is
or instanceof
is negated.