oxc-project/oxc · error
Expected a `break` statement before `default`.
Error message
Expected a `break` statement before `default`.
What it means
The same oxlint no-fallthrough rule, but the clause being fallen into is default: instead of another case:. JavaScript lets the case above default: omit a terminator and execute the default body, which readers rarely expect, so the rule flags it identically. A matching fallthrough comment suppresses the report just like case-to-case fallthrough.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_fallthrough.rs:38
};
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)
}
#[derive(Default, Debug, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct NoFallthroughConfig {
/// Custom regex pattern to match fallthrough comments.View on GitHub (pinned to e1e7af627c)
Solutions
- Add break; at the end of the case above default:.
- Move default: to the last position and make the preceding case terminate.
- Add // falls through if falling into default is intentional.
Example fix
// before
switch (size) {
case 'sm':
scale = 0.5;
default:
scale = 1;
}
// after
switch (size) {
case 'sm':
scale = 0.5;
break;
default:
scale = 1;
} Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -A all -D no-fallthrough src/ # fail the build on fallthrough only
Prevention
- Treat default: like any case when auditing terminators.
- Put default: last and make sure the case above it terminates.
- Use fallthrough comments only when fallthrough is real.
When it happens
Trigger: case 'sm': with no terminator directly above default:; a case falling into default: where the default also performs cleanup; a new case inserted above default: without a break during a feature branch.
Common situations: Cases reordered so default: ends up below a terminator-less case; if/else chains converted to switches during refactors; default moved to the middle of the switch without auditing terminators.
Related errors
- Expected a `break` statement before `case`.
- 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/c8ba90fabb6acbb6.
Report an issue: GitHub.