no-negated-in-lhs
规则在 ESLint v3.3.0 中已弃用,并由无不安全否定规则取代。
规则细节
正如开发者可能键入-a + b
时,他们的意思是-(a + b)
和的负数,他们可能会输入!key in object
错误时,他们几乎肯定意味着!(key in object)
要测试的关键是不是一个对象。
规则细节
规则不允许否定in
表达式中的左操作数。
规则的错误代码示例:
/*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
}
规则的正确代码示例:
/*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
}
何时不使用它
无
版本
规则在 ESLint 0.1.2 中引入。
资源
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com