{"record":{"id":"04cc18c214e802fa","repo":"oxc-project/oxc","slug":"enforce-default-clauses-in-switch-statements-to-be","errorCode":null,"errorMessage":"Enforce default clauses in switch statements to be last","messagePattern":"Enforce default clauses in switch statements to be last","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/default_case_last.rs","lineNumber":11,"sourceCode":"use 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};\n\nfn default_case_last_diagnostic(span: Span) -> OxcDiagnostic {\n    let default_span = Span::sized(span.start, 7);\n\n    OxcDiagnostic::warn(\"Enforce default clauses in switch statements to be last\")\n        .with_label(default_span.label(\"Default clause should be the last clause.\"))\n}\n\n#[derive(Debug, Default, Clone)]\npub struct DefaultCaseLast;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    /// Requires the `default` clause in `switch` statements to be the last one.\n    ///\n    /// ### Why is this bad?\n    /// By convention and for readability, the `default` clause should be the last one in a `switch`.\n    /// While it is legal to place it before or between `case` clauses, doing so is confusing and may\n    /// lead to unexpected \"fall-through\" behavior.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/default_case_last.rs#L1-L29","documentation":"Oxlint's port of the ESLint rule default-case-last: when a switch has a `default` clause, it must be the final clause. The diagnostic highlights exactly the keyword via Span::sized(span.start, 7) (crates/oxc_linter/src/rules/eslint/default_case_last.rs:12) and labels it 'Default clause should be the last clause.'","triggerScenarios":"Any switch where default appears before one or more case clauses, e.g. `switch (x) { default: r(); case 1: f(); }`.","commonSituations":"Reordering cases for perceived performance and leaving default on top; copy-pasted switch templates; hand-merging similar switches.","solutions":["Move the default clause to the end of the switch body.","Note that default-on-top still executes correctly at runtime (cases after it still match), so reordering is always behavior-safe."],"exampleFix":"// before\nswitch (x) {\n  default: return 0;\n  case 1: return 1;\n}\n\n// after\nswitch (x) {\n  case 1: return 1;\n  default: return 0;\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"rules\": {\n    \"default-case-last\": \"warn\"\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write switches with default last from the start; it is the universal convention.","When reordering cases, move default to the end in the same commit.","Note the keyword span is what gets labeled, so keep the clause header clean."],"tags":["eslint","oxlint","switch","clause-order","style"],"backgroundTag":"switch-default-not-last","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"}