# no-ternary

> Disallow the `? :` operator

`test ? a : b` puts a branch in the middle of an expression. Some teams find `if` and `else` easier to read, step through in a debugger and extend later, so they ban the operator everywhere. This rule reports every use of it.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-ternary" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
const label = count === 1 ? "item" : "items";
```

Not reported:

{/* good */}
```js
let label = "items";
if (count === 1) {
  label = "item";
}
```

## When not to use it

A short ternary is often the clearest way to choose between two values, and it lets the variable stay `const`. If only the nested ones bother you, use `no-nested-ternary`.
