oxc-project/oxc · error · OxcDiagnostic
Unnecessary braces in case clause.
Error message
Unnecessary braces in case clause.
What it means
Emitted by the unicorn/switch-case-braces rule (with the `convert` option) at a `case` clause that already has braces but whose body would not need them under the configured conversion policy. The braces are considered redundant and should be removed for consistency.
Solutions
- Remove the unnecessary braces from the case clause
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs:28 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/9ed666373d3cc7c9.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs:28
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))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "kebab-case")]
pub enum SwitchCaseBracesConfig {
/// Always require braces in case clauses (except empty cases).
#[default]View on GitHub (pinned to e1e7af627c)