{"record":{"id":"722b1bba4344aa95","repo":"oxc-project/oxc","slug":"duplicate-conditions-in-if-else-if-chain","errorCode":null,"errorMessage":"Duplicate conditions in if-else-if chain","messagePattern":"Duplicate conditions in if-else-if chain","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs","lineNumber":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Expression, Statement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{ContentEq, GetSpan, Span};\nuse oxc_syntax::operator::LogicalOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_dupe_else_if_diagnostic(first_test: Span, second_test: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Duplicate conditions in if-else-if chain\")\n        .with_help(\n            \"Remove or modify the duplicate condition, as its branch will never be executed.\",\n        )\n        .with_labels([\n            first_test.label(\"condition first checked here\"),\n            second_test.label(\"this branch will never be executed\"),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDupeElseIf;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow duplicate conditions in if-else-if chains.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs#L1-L31","documentation":"This diagnostic comes from the `no_dupe_else_if` rule in oxlint. It reports an `if / else if` chain where one test is structurally equal to an earlier test in the same chain. The later branch can never run, because the earlier branch already captured that condition. The rule compares test expressions with `ContentEq`, including the operands of `&&` and `||` chains.","triggerScenarios":"An `else if` whose test equals an earlier test: `if (x === 1) { a(); } else if (x === 1) { b(); }`. Overlaps inside logical operators also count, for example `if (a || b) {} else if (b || a) {}`.","commonSituations":"A long condition chain grows by copy-paste. A condition moves during refactor and the old copy stays. Flag names change mid-chain, and a duplicate slips in after a partial rename.","solutions":["Change or remove the duplicate test in the later branch.","Merge both cases into one branch with `||` when they need the same body.","Replace the chain with a lookup map or a `switch` when each test maps one value to one branch."],"exampleFix":"// before\nif (role === 'admin') {\n  showPanel();\n} else if (role === 'admin') {\n  showSecretPanel();\n}\n\n// after\nif (role === 'admin') {\n  showPanel();\n  showSecretPanel();\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write each `else if` condition from scratch; never copy a branch.","Run oxlint while you edit so the second label points at the unreachable branch at once.","Prefer a map or `switch` for value dispatch over long chains."],"tags":["javascript","eslint","lint","logic","dead-code"],"backgroundTag":"lint-duplicate-condition","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"}