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

  1. Add break; at the end of the case above default:.
  2. Move default: to the last position and make the preceding case terminate.
  3. 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

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


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/c8ba90fabb6acbb6. Report an issue: GitHub.