# no-ternary

Rule `eslint/no-ternary`. Disallow ternary operators

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1651 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-ternary` | no | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-ternary) |
| Oxlint | `no-ternary` | no | no | plugin `eslint`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-ternary.html) |
| Biome | `style/noTernary` | no | no | group style, since 2.3.8 | [docs](https://biomejs.dev/linter/rules/no-ternary/) |

## Code examples

### Incorrect: the rule reports this

```js
const foo = isBar ? baz : qux;

function quux() {
  return foo ? bar() : baz();
}
```

### Correct: the rule accepts this

```js
let foo;

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

function quux() {
    if (foo) {
        return bar();
    } else {
        return baz();
    }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "no-ternary": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-ternary": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "noTernary": "error"
      }
    }
  }
}
```

## Related rules

- [eslint/no-magic-numbers](https://lintradar.dev/rules/eslint/no-magic-numbers.md): Disallow magic numbers
- [eslint/max-statements](https://lintradar.dev/rules/eslint/max-statements.md): Enforce a maximum number of statements allowed in function blocks
- [eslint/max-lines-per-function](https://lintradar.dev/rules/eslint/max-lines-per-function.md): Enforce a maximum number of lines of code in a function
- [eslint/init-declarations](https://lintradar.dev/rules/eslint/init-declarations.md): Require or disallow initialization in variable declarations
- [eslint/require-atomic-updates](https://lintradar.dev/rules/eslint/require-atomic-updates.md): Disallow assignments that can lead to race conditions due to usage of `await` or `yield`
- [eslint/capitalized-comments](https://lintradar.dev/rules/eslint/capitalized-comments.md): Enforce or disallow capitalization of the first letter of a comment

---

Web page: https://lintradar.dev/rules/eslint/no-ternary. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
