no-ternary
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-ternary": "error",
},
},
];const foo = isBar ? baz : qux;
function quux() {
return foo ? bar() : baz();
}let foo;
if (isBar) {
foo = baz;
} else {
foo = qux;
}
function quux() {
if (foo) {
return bar();
} else {
return baz();
}
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
no-ternary
eslint
export default [
{
rules: {
"no-ternary": "error",
},
},
];no-ternary
eslint plugin · style
{
"rules": {
"no-ternary": "error"
}
}style/noTernary
style · since 2.3.8
{
"linter": {
"rules": {
"style": {
"noTernary": "error"
}
}
}
}Enforce a maximum number of statements allowed in function blocks
Enforce a maximum number of lines of code in a function
Require or disallow initialization in variable declarations
Disallow assignments that can lead to race conditions due to usage of await or yield
Enforce or disallow capitalization of the first letter of a comment