{"record":{"id":"5e4ca447fe5c7551","repo":"oxc-project/oxc","slug":"prefer-using-a-logical-operator-over-a-ternary","errorCode":null,"errorMessage":"Prefer using a logical operator over a ternary.","messagePattern":"Prefer using a logical operator over a ternary\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::UnaryOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_same_expression};\n\nfn prefer_logical_operator_over_ternary_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer using a logical operator over a ternary.\")\n        .with_help(\"Switch to \\\"||\\\" or \\\"??\\\" operator\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferLogicalOperatorOverTernary;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule finds ternary expressions that can be simplified to a logical operator.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using a logical operator is shorter and simpler than a ternary expression.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs#L1-L28","documentation":"Diagnostic from the unicorn/prefer-logical-operator-over-ternary lint rule. It fires when a conditional expression returns one of its branches directly, e.g. `a ? a : b` or `a ? b : a`; the logical operators `||` or `??` express the same fallback semantics more concisely. The flagged input is the ternary expression whose branches duplicate a condition operand. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs:10 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite `a ? a : b` as `a || b` when truthiness is intended","Use `a ?? b` when only `null`/`undefined` should fall through","Apply the rule's auto-fix"],"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"}