oxc-project/oxc · error
Expected a `break` statement before `case`.
Error message
Expected a `break` statement before `case`.
What it means
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).
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_fallthrough.rs:32
use oxc_cfg::{
BlockNodeId, EdgeType, ErrorEdgeKind, InstructionKind,
graph::{
Direction,
visit::{EdgeRef, neighbors_filtered_by_edge_weight},
},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn no_fallthrough_case_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected a `break` statement before `case`.")
.with_help("Use a `break` statement to prevent fallthrough, or add a comment to indicate intentional fallthrough.")
.with_label(span)
}
fn no_fallthrough_default_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Expected a `break` statement before `default`.")
.with_help("Use a `break` statement to prevent fallthrough, or add a comment to indicate intentional fallthrough.")
.with_label(span)
}
fn no_unused_fallthrough_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"Found a comment that would permit fallthrough, but case cannot fall through.",
)
.with_help(
"Remove the fallthrough comment or add code that allows fallthrough (e.g. remove `break`).",
)
.with_label(span)View on GitHub (pinned to e1e7af627c)
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.
Example fix
// before
switch (code) {
case 1:
log('one');
case 2:
log('two');
break;
}
// after
switch (code) {
case 1:
log('one');
break;
case 2:
log('two');
break;
} Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -A all -D no-fallthrough src/ # fail the build on fallthrough only
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected a `break` statement before `default`.
- Checking `switch` discriminant against NaN will never match
- Checking for NaN in `case` clause will never match
- Found a comment that would permit fallthrough, but case cann
- Unnecessary return statement.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/ed9287740c5fe54e.
Report an issue: GitHub.