# no-unneeded-ternary

> Disallow `? :` where the condition alone says the same

`age >= 18 ? true : false` is a long way to write `age >= 18`.

`--fix` rewrites the expression: `a === b ? true : false` becomes `a === b`, `user ? true : false` becomes `!!user`, and `user ? false : true` becomes `!user`.

{/* 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-unneeded-ternary" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-unneeded-ternary" = ["error", {
  defaultAssignment = true,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const isAdult = age >= 18 ? true : false;
const isGuest = user ? false : true;
```

Not reported:

{/* good */}
```js
const isAdult = age >= 18;
const isGuest = !user;
const label = isAdult ? "adult" : "minor";
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `defaultAssignment` | `true` | Allow `x ? x : fallback`. Set it to `false` to report that too. |

{/* good */}
```js
const title = name ? name : "Untitled";
```

{/* bad {"options": [{"defaultAssignment": false}]} */}
```js
const title = name ? name : "Untitled";
```

With `false`, `--fix` rewrites it with `||`:

{/* good {"options": [{"defaultAssignment": false}]} */}
```js
const title = name || "Untitled";
```
