in
expressions (no-negated-in-lhs)This rule was deprecated in ESLint v3.3.0 and replaced by the no-unsafe-negation rule.
Just as developers might type -a + b
when they mean -(a + b)
for the negative of a sum, they might type !key in object
by mistake when they almost certainly mean !(key in object)
to test that a key is not in an object.
This rule disallows negating the left operand in in
expressions.
Examples of incorrect code for this rule:
/*eslint no-negated-in-lhs: "error"*/
if(!key in object) {
// operator precedence makes it equivalent to (!key) in object
// and type conversion makes it equivalent to (key ? "false" : "true") in object
}
Examples of correct code for this rule:
/*eslint no-negated-in-lhs: "error"*/
if(!(key in object)) {
// key is not in object
}
if(('' + !key) in object) {
// make operator precedence and type conversion explicit
// in a rare situation when that is the intended meaning
}
Never.
This rule was introduced in ESLint 0.1.2.
© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/no-negated-in-lhs