Description
Currently no-nested-ternary permits single-level nesting only when wrapped in parentheses, and deeply nested ternaries (3+ levels) are always rejected. This creates a well-documented conflict with Prettier (#2604), which removes the parentheses the auto-fixer adds — producing a circular fix loop.
eslint-config-prettier resolves this by disabling the rule entirely, but this throws away the valuable deep-nesting protection.
I'd like to propose an option (e.g. allowSingleNesting: true) that permits single-level nesting without requiring parentheses, while still rejecting deep nesting. This would let projects use Prettier and still benefit from the rule for multi-level ternaries.
Examples
With "unicorn/no-nested-ternary": ["error", { "allowSingleNesting": true }]:
// Pass — single-level nesting, no parens needed
const foo = a ? b : c ? d : e;
// Pass — single-level nesting with parens (still fine)
const foo = a ? (b > 1 ? x : y) : z;
// Fail — deep nesting (3+ levels)
const foo = a ? b : c ? d : e ? f : g;
Additional info
Description
Currently
no-nested-ternarypermits single-level nesting only when wrapped in parentheses, and deeply nested ternaries (3+ levels) are always rejected. This creates a well-documented conflict with Prettier (#2604), which removes the parentheses the auto-fixer adds — producing a circular fix loop.eslint-config-prettierresolves this by disabling the rule entirely, but this throws away the valuable deep-nesting protection.I'd like to propose an option (e.g.
allowSingleNesting: true) that permits single-level nesting without requiring parentheses, while still rejecting deep nesting. This would let projects use Prettier and still benefit from the rule for multi-level ternaries.Examples
With
"unicorn/no-nested-ternary": ["error", { "allowSingleNesting": true }]:Additional info
no-nested-ternaryconflicts withprettier#2604 documents the Prettier conflicta ? b : c ? d : einto if/else — which can hurt readability for simple cases