Skip to content
← Back to rules

unicorn/no-negation-in-equality-check Pedantic

💡 A suggestion is available for this rule.

它的作用

禁止在(不)相等检查的左侧使用取反表达式。

为什么这不好?

在(不)相等检查左侧使用取反表达式,很可能是因为尝试对整个条件取反而产生的错误。

示例

该规则的不正确代码示例:

javascript
if (!foo === bar) {
}

if (!foo !== bar) {
}

该规则的正确代码示例:

javascript
if (foo !== bar) {
}

if (!(foo === bar)) {
}

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-negation-in-equality-check": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-negation-in-equality-check": "error",
  },
});
bash
oxlint --deny unicorn/no-negation-in-equality-check

版本

此规则于 v0.5.3 中添加。

参考资料