Aller au contenu

noTernary

Ce contenu n’est pas encore disponible dans votre langue.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noTernary": "error"
}
}
}
}

Disallow ternary operators.

The ternary operator is used to conditionally assign a value to a variable. Some believe that the use of ternary operators leads to unclear code.

const foo = isBar ? baz : qux;
code-block.js:1:13 lint/nursery/noTernary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected ternary operator.

> 1 │ const foo = isBar ? baz : qux;
^^^^^^^^^^^^^^^^^
2 │

Ternary operators can lead to unclear code. Use if-else statement instead.

let foo;
if (isBar) {
foo = baz;
} else {
foo = qux;
}