oxc-project/oxc · error · OxcDiagnostic

Unexpected nested ternary expression without parentheses.

Error message

Unexpected nested ternary expression without parentheses.

What it means

Raised by unicorn/no-nested-ternary (with its default parens mode) when a ternary appears nested inside another ternary without enclosing parentheses, hurting readability and parse intent. The faulting input is the unparenthesized nested conditional at the labeled span.

Solutions

  1. Add parentheses around the nested ternary to make grouping explicit
  2. Refactor the chain into if/else statements or a lookup map for clarity
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/4ba0a291efdf309d. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs:9

use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule};

fn unparenthesized_nested_ternary(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected nested ternary expression without parentheses.")
        .with_help("Add parentheses around the nested ternary expression.")
        .with_label(span)
}

fn deeply_nested_ternary(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected deeply nested ternary expression.")
        .with_help("Avoid nesting ternary expressions for more than one level.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoNestedTernary;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow deeply nested ternary expressions.
    ///

View on GitHub (pinned to e1e7af627c)