oxc-project/oxc · error · OxcDiagnostic
Missing braces in case clause.
Error message
Missing braces in case clause.
What it means
Emitted by the unicorn/switch-case-braces rule when a `case` clause contains lexical declarations (`let`/`const`/`class`) but has no surrounding braces. Braces are required there so the declarations get their own block scope and cannot leak into the shared switch-block scope.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs:22
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
AstNode,
ast_util::get_preceding_indent_str,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn switch_case_braces_diagnostic_empty_clause(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected braces in empty case clause.")
.with_help("Remove braces in empty case clause.")
.with_label(span)
}
fn switch_case_braces_diagnostic_missing_braces(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing braces in case clause.")
.with_help("Add Braces for case clause.")
.with_label(span)
}
fn switch_case_braces_diagnostic_unnecessary_braces(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unnecessary braces in case clause.")
.with_help("Remove Braces for case clause.")
.with_label(span)
}
#[derive(Debug, Clone, Deserialize)]
pub struct SwitchCaseBraces(Box<SwitchCaseBracesConfig>);
impl Default for SwitchCaseBraces {
fn default() -> Self {
Self(Box::new(SwitchCaseBracesConfig::Always))
}
}View on GitHub (pinned to e1e7af627c)
Solutions
- Wrap the case clause body in braces: `case 'a': { ... break; }`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs:22 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/426ddd3e313d1a31.
Report an issue: GitHub.