{"record":{"id":"b4dc563d24704969","repo":"oxc-project/oxc","slug":"require-default-cases-in-switch-statements","errorCode":null,"errorMessage":"Require `default` cases in `switch` statements.","messagePattern":"Require `default` cases in `switch` statements\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/default_case.rs","lineNumber":17,"sourceCode":"use lazy_regex::{Regex, RegexBuilder};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn default_case_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Require `default` cases in `switch` statements.\")\n        .with_help(\"Add a `default` case.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct DefaultCase(Box<DefaultCaseConfig>);\n\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct DefaultCaseConfig {\n    /// A regex pattern used to detect comments that mark the absence\n    /// of a `default` case as intentional.\n    ///\n    /// Default value: `no default`.\n    ///\n    /// Examples of **incorrect** code for this rule with the `{ \"commentPattern\": \"^skip\\\\sdefault\" }` option:\n    /// ```js\n    /// switch (a) {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/default_case.rs#L1-L35","documentation":"Oxlint's port of the ESLint rule default-case: every `switch` statement must contain a `default` clause. The diagnostic is default_case_diagnostic (crates/oxc_linter/src/rules/eslint/default_case.rs:16) with help 'Add a `default` case.' DefaultCaseConfig carries `commentPattern`, a regex; when a comment inside the switch matches it, the missing default is treated as intentional and not reported.","triggerScenarios":"Linting any switch that has case clauses but no default clause and no comment matching the configured commentPattern (unset by default, so any comment opt-out requires configuring the pattern).","commonSituations":"Switches over enums believed to be exhaustive; migrating an ESLint config whose commentPattern (e.g. \"^no default$\") was not carried over; teammates unaware of the comment-based opt-out.","solutions":["Add an explicit default clause to the switch, even a throwing or no-op one.","If omitting default is intentional, add a comment that matches the configured commentPattern, e.g. `// no default`.","Configure commentPattern in .oxlintrc.json to your team's marker comment.","Disable the rule when exhaustiveness is already enforced by TypeScript's never check."],"exampleFix":"// before\nswitch (kind) {\n  case 'a': return 1;\n  case 'b': return 2;\n}\n\n// after\nswitch (kind) {\n  case 'a': return 1;\n  case 'b': return 2;\n  default:\n    throw new Error(kind);\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — configure the intentional-omission marker comment\n{\n  \"rules\": {\n    \"default-case\": [\"warn\", { \"commentPattern\": \"^no default$\" }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make every switch exhaustive with an explicit default, especially over unions.","Configure commentPattern once so `// no default` comments are honored.","For TypeScript, combine with a `assertNever`-style default so new union members fail the build."],"tags":["eslint","oxlint","switch","default-case"],"backgroundTag":"switch-missing-default-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"}