eslint/no-nested-ternary 样式
作用
禁止嵌套的三元表达式。
为什么这是不好的?
嵌套的三元表达式会使代码更难阅读和理解。这类表达式的嵌套可能导致 复杂且难以理解的逻辑。
示例
以下是此规则的错误代码示例:
js
const result = condition1 ? (condition2 ? "a" : "b") : "c";以下是此规则的正确代码示例:
js
let result;
if (condition1) {
result = condition2 ? "a" : "b";
} else {
result = "c";
}How to Use
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-nested-ternary": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-nested-ternary": "error",
},
});bash
oxlint --deny no-nested-ternary版本
此规则在 v0.15.4 中添加。
