# Nested Ternary
# Detects deeply nested ternary operators (readability issue)
id: nested-ternary
name: Nested Ternary
severity: warning
category: readability
defect_class: safety
inline_tier: review
language: typescript

message: "Nested ternary — use if/else or early returns for clarity"

description: |
  Nested ternary operators are hard to read and understand.
  Prefer if/else statements or early returns.
  
  ✅ FIX: Use if/else or switch statement

query: |
  (ternary_expression
    consequence: (ternary_expression) @NESTED)
  (ternary_expression
    alternative: (ternary_expression) @NESTED)

metavars:
  - NESTED

tags:
  - readability
  - code-quality

examples:
  bad: |
    const value = condition1 
      ? condition2 
        ? condition3 ? "a" : "b"
        : "c"
      : "d";
  
  good: |
    function getValue(c1, c2, c3) {
      if (!c1) return "d";
      if (!c2) return "c";
      return c3 ? "a" : "b";
    }

has_fix: false
