Skip to content
← Back to rules

oxc/double-comparisons Correctness

This rule is turned on by default.
🛠️ An auto-fix is available for this rule.

它的作用

此规则检查逻辑表达式中的重复比较。

这为什么不好?

冗余的比较可能会令人困惑,并使代码更难理解。

示例

此规则的错误代码示例:

javascript
x === y || x < y;
x < y || x === y;

此规则的正确代码示例:

javascript
x <= y;
x >= y;

如何使用

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

json
{
  "rules": {
    "oxc/double-comparisons": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/double-comparisons": "error",
  },
});
bash
oxlint --deny oxc/double-comparisons

版本

此规则在 v0.0.22 中添加。

参考资料