switch-case-spacing
Enforce consistent spacing and break placement in switch cases.
Targeted pattern scopeโ
This rule inspects each SwitchCase body and enforces a specific structure for
non-empty cases.
For non-empty cases, it expects:
- the first consequent statement starts on a later line than
case ...:; and - the case ends with
break, unless the case body starts with a block statement.
What this rule reportsโ
This rule reports switch case bodies that do not match the expected spacing/break style.
Why this rule existsโ
This rule enforces a strict legacy switch layout policy to keep case bodies visually consistent.
โ Incorrectโ
switch (x) {
case 1:
foo();
}
โ Correctโ
switch (x) {
case 1: {
foo();
}
}
Deprecatedโ
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
@stylistic/switch-colon-spacing
Behavior and migration notesโ
This rule is deprecated in favor of @stylistic/switch-colon-spacing.
It reports only and does not provide an autofix.
Optionsโ
This rule has no options.
Statusโ
Use the Deprecated section above for lifecycle details.
Additional examplesโ
switch (status) {
case "ok":
doWork();
break;
// โ first statement is on same line as `case`
case "done":
doWork();
break;
// โ
valid
}
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/switch-case-spacing": "error",
},
},
];
When not to use itโ
Disable this rule if your switch formatting is handled by a different style policy.
Package documentationโ
Rule catalog ID: R072
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.