Eslint参考手册
规则 | Rules
no-eq-null
与null
没有类型检查运算符(==
或!=
)的情况相比,可能会产生意想不到的结果,因为比较结果不仅仅是null
一个undefined
值,而是一个值。
if (foo == null) {
bar();
}
规则细节
该no-eq-null
规则旨在通过确保比较null
仅匹配null
而不是另外来减少潜在的错误和不需要的行为undefined
。因此,使用==
和时它会将比较标记为空!=
。
此规则的错误代码示例:
/*eslint no-eq-null: "error"*/
if (foo == null) {
bar();
}
while (qux != null) {
baz();
}
此规则的正确代码示例:
/*eslint no-eq-null: "error"*/
if (foo === null) {
bar();
}
while (qux !== null) {
baz();
}
版本
该规则在 ESLint 0.0.9 中引入。
资源
- 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 |