Skip to content
← Back to rules

eslint/no-self-compare Pedantic

作用

禁止两边完全相同的比较。

为什么这不好?

将变量与自身进行比较通常是错误,可能是拼写错误或重构错误。 这会让读者感到困惑,并且可能引入运行时错误。

示例

以下是此规则的错误代码示例:

javascript
var x = 10;
if (x === x) {
  x = 20;
}

如何使用

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

json
{
  "rules": {
    "no-self-compare": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-self-compare": "error",
  },
});
bash
oxlint --deny no-self-compare

版本

此规则在 v0.0.3 中添加。

参考资料