oxc-project/oxc · error · OxcDiagnostic
Do not nest ternary expressions.
Error message
Do not nest ternary expressions.
What it means
Lint diagnostic from eslint/no-nested-ternary: a ternary expression appears inside the consequent or alternate of another ternary. Nested conditionals are hard to parse visually and easy to get wrong when editing.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs:10
use oxc_ast::AstKind;
use oxc_ast::ast::Expression;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_nested_ternary_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not nest ternary expressions.")
.with_help(
"Refactor nested ternary expressions into if-else statements for better readability.",
)
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNestedTernary;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow nested ternary expressions.
///
/// ### Why is this bad?
///
/// Nested ternary expressions make code harder to read and understand. Nesting of these expressions can lead
/// to complex logic that is difficult to understand.View on GitHub (pinned to e1e7af627c)
Solutions
- Refactor into if/else statements
- Extract each level into a named variable or helper function
- Use a lookup table or switch for multi-way selection
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_nested_ternary.rs:10 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/3b50e3815a457ee9.
Report an issue: GitHub.