Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Inconsistent brace usage in switch statements makes code harder to scan and can introduce scope-related bugs when adding statements to an existing case. This rule enforces a single consistent style: by default, every non-empty case clause must be wrapped in a block ({}), and empty clauses must not have braces.
Recommendedrecommended
Fixable🔧 Auto-fixable
Suggestions
switch (foo) {
  // Empty clause must not have braces
  case 1: {
  }
  // Non-empty clause must be wrapped in a block
  case 2:
    doSomething();
    break;
}

Why braces for non-empty clauses?

Block statements create a new lexical scope, which is required for const and let declarations inside a case. Enforcing braces consistently avoids the need to add them reactively when a variable declaration is introduced later, and makes fall-through intent more explicit.

Configuration options

Type: string
Default: "always"
Pass a single string option to switch enforcement modes.

"always" (default)

Every non-empty case clause must be wrapped in a BlockStatement. Empty clauses must not have braces.
"unicorn/switch-case-braces": ["error", "always"]

"avoid"

Braces are only required when the clause contains a const/let declaration or a function declaration that needs its own scope. All other non-empty clauses must not use braces.
"unicorn/switch-case-braces": ["error", "avoid"]
/* eslint unicorn/switch-case-braces: ["error", "avoid"] */

switch (foo) {
  // Braces are unnecessary — no declarations inside
  case 1: {
    doSomething();
    break;
  }
}

Build docs developers (and LLMs) love