oxc-project/oxc · error · OxcDiagnostic

Move `{keyword}` inside the block statement.

Error message

Move `{keyword}` inside the block statement.

What it means

Emitted by the unicorn/switch-case-break-position rule when a `break`, `return`, `continue`, or `throw` statement sits directly in a case clause that has braces, instead of inside the block statement. The rule enforces a consistent position so control flow is visually unambiguous.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_break_position.rs:9

use oxc_ast::{AstKind, ast::Statement};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule};

fn switch_case_break_position_diagnostic(span: Span, keyword: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Move `{keyword}` inside the block statement.")).with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct SwitchCaseBreakPosition;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Enforce consistent `break`/`return`/`continue`/`throw` position in `case` clauses.
    ///
    /// ### Why is this bad?
    ///
    /// Enforce that terminating statements (`break`, `return`, `continue`, `throw`) appear inside the block statement of a `case` clause, not after it.
    /// This can happen when refactoring — for example, removing an `if` wrapper but leaving the `break` outside the braces.
    ///
    /// ### Examples
    ///
    /// Examples of **incorrect** code for this rule:

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Move the `break`/`return`/`continue`/`throw` statement inside the braces of the block statement
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_break_position.rs:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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