noTernary
Ta treść nie jest jeszcze dostępna w Twoim języku.
Summary
Section titled “Summary”- Rule available since:
v2.3.8 - Diagnostic Category:
lint/nursery/noTernary - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-ternary
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noTernary": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.