{"record":{"id":"2b1a98221b921d99","repo":"oxc-project/oxc","slug":"useless-case-in-switch-statement","errorCode":null,"errorMessage":"Useless case in switch statement.","messagePattern":"Useless case in switch statement\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs","lineNumber":10,"sourceCode":"use oxc_allocator::UnstableAddress;\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_empty_stmt};\n\nfn no_useless_switch_case_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Useless case in switch statement.\")\n        .with_help(\"Consider removing this case or removing the `default` case.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessSwitchCase;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows useless `default` cases in `switch` statements.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// An empty case before the last `default` case is useless, as the\n    /// `default` case will catch it regardless.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs#L1-L28","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-switch-case` (pedantic category). It fires for each case clause with an empty consequent (only empty statements, lone blocks, or nothing) that sits immediately before the final `default` clause of a `switch`. Control falls through such a case into `default` anyway, so the case label is dead. No autofix is implemented (`pending`); the help suggests removing the case or the default.","triggerScenarios":"`switch (foo) { case a: default: handle(); break; }` flags `case a:`; stacked empty cases `case a: case b: default: ...` flag every empty case; empty blocks `case a: { ;; } default:` also count. Requires exactly one `default`, positioned last; `default` in the middle, missing `default`, or any non-empty statement in the case (even just `break;`) prevents the report.","commonSituations":"Switches grown over time where a case's body was removed but its label stayed, and template-generated switches that always append a default. Appears when the oxlint pedantic category or unicorn plugin is enabled.","solutions":["Delete the empty case labels that fall straight into `default`.","If the case labels exist for documentation, either add a comment plus a `break;` (any statement silences the rule) or remove them.","If the `default` is itself unnecessary, remove `default` instead; the rule then no longer fires.","Disable inline with `oxlint-disable-next-line unicorn/no-useless-switch-case` for intentional fall-through documentation."],"exampleFix":"// before\nswitch (foo) {\n  case 1:\n  default:\n    handleDefaultCase();\n    break;\n}\n\n// after\nswitch (foo) {\n  default:\n    handleDefaultCase();\n    break;\n}","handlingStrategy":"validation","validationCode":"# detect empty case labels falling into a final default\nrg -n --type js -U 'case\\s+[^:]+:\\s*(?:case\\s+[^:]+:\\s*)*default\\s*:' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Delete case labels when you delete their bodies.","When reordering switches, keep `default` last so dead fall-throughs become visible.","Enable no-fallthrough alongside this rule to keep switch hygiene in CI."],"tags":["lint","oxlint","unicorn","switch","fall-through","dead-code","pedantic"],"backgroundTag":"useless-switch-case","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"}