{"record":{"id":"212f79e9c3968624","repo":"oxc-project/oxc","slug":"unexpected-deeply-nested-ternary-expression","errorCode":null,"errorMessage":"Unexpected deeply nested ternary expression.","messagePattern":"Unexpected deeply nested ternary expression\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs","lineNumber":15,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn unparenthesized_nested_ternary(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected nested ternary expression without parentheses.\")\n        .with_help(\"Add parentheses around the nested ternary expression.\")\n        .with_label(span)\n}\n\nfn deeply_nested_ternary(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected deeply nested ternary expression.\")\n        .with_help(\"Avoid nesting ternary expressions for more than one level.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoNestedTernary;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow deeply nested ternary expressions.\n    ///\n    /// Nested ternary expressions that are only one level deep and wrapped in parentheses are allowed by this rule.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Nesting ternary expressions can make code more difficult to understand.\n    ///","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs#L1-L33","documentation":"Raised by unicorn/no-nested-ternary when ternaries are nested more than one level deep (a ternary inside a parenthesized nested ternary), exceeding the rule's depth allowance. The faulting input is the deeply nested conditional chain at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs:15 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Flatten the logic into if/else statements or a switch","Extract nested conditionals into well-named helper variables or functions","Replace multi-way branching with a lookup table/object"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}