disallow-nested-ternary-unfold-to-if-else
Unfold nested JavaScript-family ternaries into explicit if / else if / else statements when the ternary appears in a statement-safe context.
What It Transforms
This codemod rewrites nested ConditionalExpression trees in these contexts:
- Single-declarator
let/varinitializers - Assignment expression statements
- Return statements
- Expression-bodied arrow functions whose body is the nested ternary
Examples:
js
becomes:
js
js
becomes:
js
No-Op Cases
The codemod leaves these shapes unchanged:
- Single-level ternaries
constdeclarator initializers- Multi-declarator variable declarations
- Nested ternaries in call arguments
- Nested ternaries in JSX prop expressions
- Nested ternaries in template literal interpolations
- Nested ternaries in loop headers
- Assignment expressions whose operator is not plain
= - Assignment expressions whose left-hand side is not a bare identifier
- Nodes preceded by
codemod-ignore no-nested-ternary
File Coverage
The workflow runs the TSX parser across *.js, *.jsx, *.mjs, *.cjs, *.ts, and *.tsx files so JSX and TypeScript syntax can coexist with plain JavaScript input.
This codemod is intentionally conservative in declaration and assignment contexts where preserving JavaScript runtime semantics would otherwise be ambiguous.
Usage
bash
Development
bash
License
MIT