Disallow negated left operand of in operator (no-negated-in-lhs)

Rule Details

This rule is raised to highlight a potential error. Commonly, when a developer intends to write

if(!(a in b)) {
    // do something
}

they will instead write

if(!a in b) {
    // do something
}

If one intended the original behaviour, the left operand should be explicitly coerced to a string like below.

if(('' + !a) in b) {
    // do something
}

The following patterns are considered problems:

/*eslint no-negated-in-lhs: 2*/

if(!a in b) {       /*error The 'in' expression's left operand is negated*/
    // do something
}

The following patterns are not considered problems:

/*eslint no-negated-in-lhs: 2*/

if(!(a in b)) {
    // do something
}

if(('' + !a) in b) {
    // do something
}

When Not To Use It

Never.

Further Reading

None.

Version

This rule was introduced in ESLint 0.1.2.

Resources