switch-case-braces

March 27, 2026 Β· View on GitHub

πŸ“ Enforce consistent brace style for case clauses.

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

  1. Forbid braces for empty clauses.
  2. Enforce braces for non-empty clauses.

Examples

// ❌
switch (foo) {
	case 1: {
	}
	case 2: {
		doSomething();
		break;
	}
}

// βœ…
switch (foo) {
	case 1:
	case 2: {
		doSomething();
		break;
	}
}
// ❌
switch (foo) {
	case 1:
		doSomething();
		break;
}

// βœ…
switch (foo) {
	case 1: {
		doSomething();
		break;
	}
}

Options

Type: string
Default: 'always'

  • 'always' (default)
    • Always report when clause is not a BlockStatement.
  • 'avoid'
    • Only allow braces when there are variable declaration or function declaration which requires a scope.

The following cases are considered valid:

/* eslint unicorn/switch-case-braces: ["error", "avoid"] */
switch (foo) {
	case 1:
		doSomething();
		break;
}
/* eslint unicorn/switch-case-braces: ["error", "avoid"] */
switch (foo) {
	case 1: {
		const bar = 2;
		doSomething(bar);
		break;
	}
}

The following case is considered invalid:

/* eslint unicorn/switch-case-braces: ["error", "avoid"] */
switch (foo) {
	case 1: {
		doSomething();
		break;
	}
}