oxc-project/oxc · warning
Found a comment that would permit fallthrough, but case…
Error message
Found a comment that would permit fallthrough, but case cannot fall through.
What it means
The inverse diagnostic of oxlint's no-fallthrough rule: a case contains a comment that matches the fallthrough pattern (e.g. '// falls through'), but the case cannot actually fall through because it ends with break/return/throw or is the last clause. The comment is dead and misleading, so the rule reports it and asks you to remove it or make the fallthrough real.
Solutions
- Delete the stale // falls through comment.
- If fallthrough was intended, remove the break/return that prevents it.
- Reword the comment so it no longer matches commentPattern when it describes something else.
Example fix
// before case 2: flush(); // falls through break; // after case 2: flush(); break;
Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -A all -D no-fallthrough src/ # catches unused fallthrough comments too
Prevention
- When adding a terminator to a case, delete its fallthrough comment in the same commit.
- Never write 'falls through' next to code that already ends in return/throw/break.
- Treat this diagnostic as a doc-rot signal during code review.
When it happens
Trigger: case 2: flush(); // falls through followed by break; on the next line; a last case or default: ending with a fallthrough comment; a return added above an old fallthrough comment during a bugfix, leaving the marker behind.
Common situations: A bugfix adds a return/break but keeps the old marker; cases are reordered so a marked case becomes terminal; fallthrough comments are copy-pasted across cases during merges.
Related errors
- Checking for NaN in `case` clause will never match
- Checking `switch` discriminant against NaN will never match
- Expected a `break` statement before `case`.
- Expected a `break` statement before `default`.
- Unexpected comment inline with code
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/2afa99a8acd4821a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/eslint/no_fallthrough.rs:44
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.
#[serde(default, deserialize_with = "deserialize_comment_pattern")]
comment_pattern: Option<Regex>,
/// Whether to allow empty case clauses to fall through.
allow_empty_case: bool,
/// Whether to report unused fallthrough comments.
report_unused_fallthrough_comment: bool,View on GitHub (pinned to e1e7af627c)