Dont-Negate-Is-Instanceof-Operands
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery rule id: dont-negate-is-instanceof-operands
Section titled “Sourcery rule id: dont-negate-is-instanceof-operands”Description
Section titled “Description”in and instanceof have lower precedence than negation operators.
if (!"prop" in myObj) { // Noncompliant; "in" operator is checking property "false" doTheThing(); // this block will be never executed}Explanation
Section titled “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.