Eslint参考手册
规则 | Rules
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 中引入。
资源
- Rule source
- Documentation source
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |