oxc/bad-comparison-sequence Correctness
它的作用
当比较运算符连续使用两次或更多次时,此规则会生效。
为什么这不好?
因为比较运算符是二元运算符,所以不可能一次比较三个或更多操作数。 如果使用比较运算符来比较三个或更多操作数,那么只有前两个操作数会被比较,其余部分会与其布尔类型结果进行比较。
示例
以下是此规则的错误代码示例:
javascript
if ((a == b) == c) {
console.log("a, b, and c are the same");
}以下是此规则的正确代码示例:
javascript
if (a == b && b == c) {
console.log("a, b, and c are the same");
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"oxc/bad-comparison-sequence": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"oxc/bad-comparison-sequence": "error",
},
});bash
oxlint --deny oxc/bad-comparison-sequence版本
此规则于 v0.0.3 中添加。
