close

no-nested-ternary

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-nested-ternary': 'error',
    },
  },
]);

Rule Details

Disallows nested ternary expressions. Nesting ternary expressions can make code more difficult to understand; prefer an if statement or extract the logic into named variables.

Examples of incorrect code for this rule:

var thing = foo ? bar : baz === qux ? quxx : foobar;

foo ? (baz === qux ? quxx : foobar) : bar;

Examples of correct code for this rule:

var thing = foo ? bar : foobar;

var thing;
if (foo) {
  thing = bar;
} else if (baz === qux) {
  thing = quxx;
} else {
  thing = foobar;
}

Original Documentation