{"record":{"id":"a32c6a38c256b731","repo":"oxc-project/oxc","slug":"duplicate-case-label","errorCode":null,"errorMessage":"Duplicate case label","messagePattern":"Duplicate case label","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_duplicate_case.rs","lineNumber":9,"sourceCode":"use oxc_ast::ast::Expression;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{ContentEq, GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_duplicate_case_diagnostic(first: Span, second: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Duplicate case label\")\n        .with_help(\"Remove the duplicated case\")\n        .with_labels([first.label(\"This label here\"), second.label(\"is duplicated here\")])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDuplicateCase;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow duplicate case labels.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// If a switch statement has duplicate test expressions in case clauses,\n    /// it is likely that a programmer copied a case clause but forgot to change the test expression.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_duplicate_case.rs#L1-L27","documentation":"This diagnostic comes from the `no_duplicate_case` rule in oxlint. It reports a `switch` statement with two `case` labels whose test expressions are structurally equal. The second case can never run, because the first one already matches. The rule compares each case test with `ContentEq` and reports the later duplicate with both spans labeled.","triggerScenarios":"A switch with a repeated test: `switch (x) { case 1: a(); break; case 1: b(); break; }`, or a repeated string case such as `case 'active':` twice.","commonSituations":"A large status-code switch grows over time, and one code is added twice. Constants are inlined as literals during refactor, and two literals now hold the same value. A case block is copied as a starting point.","solutions":["Remove the later duplicate case; its body is unreachable.","Merge both bodies into one case when both actions are needed.","Move the tests to named constants so equal values become visible at a glance."],"exampleFix":"// before\nswitch (status) {\n  case 'open':\n    start();\n    break;\n  case 'open':\n    reset();\n    break;\n}\n\n// after\nswitch (status) {\n  case 'open':\n    start();\n    reset();\n    break;\n}","handlingStrategy":"validation","validationCode":"// author-time check for generated switches\nconst tests = cases.map(c => JSON.stringify(c.test));\nconst dup = tests.filter((t, i) => tests.indexOf(t) !== i);\nif (dup.length) throw new Error('duplicate case: ' + dup[0]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer a map from value to handler; duplicate keys then fail fast in tests.","Group related cases with fall-through instead of copying a test.","Give case values named constants so equal values are visible."],"tags":["javascript","eslint","lint","switch","dead-code"],"backgroundTag":"lint-duplicate-case","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}