{"record":{"id":"ed9287740c5fe54e","repo":"oxc-project/oxc","slug":"expected-a-break-statement-before-case","errorCode":null,"errorMessage":"Expected a `break` statement before `case`.","messagePattern":"Expected a `break` statement before `case`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_fallthrough.rs","lineNumber":32,"sourceCode":"use oxc_cfg::{\n    BlockNodeId, EdgeType, ErrorEdgeKind, InstructionKind,\n    graph::{\n        Direction,\n        visit::{EdgeRef, neighbors_filtered_by_edge_weight},\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_fallthrough_case_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected a `break` statement before `case`.\")\n        .with_help(\"Use a `break` statement to prevent fallthrough, or add a comment to indicate intentional fallthrough.\")\n        .with_label(span)\n}\n\nfn no_fallthrough_default_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected a `break` statement before `default`.\")\n        .with_help(\"Use a `break` statement to prevent fallthrough, or add a comment to indicate intentional fallthrough.\")\n        .with_label(span)\n}\n\nfn no_unused_fallthrough_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Found a comment that would permit fallthrough, but case cannot fall through.\",\n    )\n    .with_help(\n        \"Remove the fallthrough comment or add code that allows fallthrough (e.g. remove `break`).\",\n    )\n    .with_label(span)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_fallthrough.rs#L14-L50","documentation":"Diagnostic from oxlint's no-fallthrough rule (ESLint port, eslint:recommended). A switch case block that reaches its end without a terminating statement (break, return, throw, continue, or an unreachable end) falls through into the next case, which is almost always a bug. The rule flags the missing break before the next case unless the case ends with a comment matching the fallthrough comment pattern ('// falls through' by default, configurable via commentPattern).","triggerScenarios":"case 1: whose last statement is a plain expression followed by case 2:; a case ending in a let/const declaration (declarations do not terminate); deliberate fallthrough without a '// falls through' comment; a custom commentPattern regex that no longer matches the team's marker spelling.","commonSituations":"A refactor deletes the last line of a case and the break goes with it; merging switch branches without adding a fallthrough comment; teams commenting in another language (e.g. '// cae en cascada') while the config expects the English marker.","solutions":["Add break; (or an early return/throw) at the end of the case block.","If the fallthrough is intentional, end the case with // falls through (or a comment matching your commentPattern).","Fix the rule's commentPattern regex in .oxlintrc.json if your team writes a different marker."],"exampleFix":"// before\nswitch (code) {\n  case 1:\n    log('one');\n  case 2:\n    log('two');\n    break;\n}\n\n// after\nswitch (code) {\n  case 1:\n    log('one');\n    break;\n  case 2:\n    log('two');\n    break;\n}","handlingStrategy":"validation","validationCode":"npx oxlint -A all -D no-fallthrough src/  # fail the build on fallthrough only","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Finish every case with break, return, throw, or continue unless deliberately falling through.","Mark intentional fallthrough with // falls through exactly as commentPattern expects.","Keep commentPattern in .oxlintrc.json in sync with the marker the team actually writes."],"tags":["eslint","oxlint","lint","switch","control-flow"],"backgroundTag":"switch-case-fallthrough","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"}