oxc/bad-comparison-sequence 正确性
功能说明
当比较运算符被连续使用两次或更多次时,此规则适用。
为什么不好?
因为比较运算符是二元运算符,不可能同时比较三个或更多操作数。如果使用比较运算符来比较三个或更多操作数,只有前两个操作数会被比较,其余部分会与布尔类型的结果进行比较。
示例
此规则的错误代码示例:
javascript
if ((a == b) == c) {
console.log("a、b 和 c 相同");
}此规则的正确代码示例:
javascript
if (a == b && b == c) {
console.log("a、b 和 c 相同");
}如何使用
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 中添加。