default-case
Require a default branch in switch statements.
Targeted pattern scope
This rule targets all JavaScript and TypeScript switch statements.
What this rule reports
This rule reports switch statements that do not include a default case.
Why this rule exists
Missing defaults can silently ignore unexpected values and create fragile control flow.
❌ Incorrect
switch (status) {
case "open":
break;
}
✅ Correct
switch (status) {
case "open":
break;
default:
break;
}
Behavior and migration notes
This rule forwards options and behavior to ESLint core default-case.
Additional examples
switch (kind) {
case "a":
runA();
break;
}
// ❌ reported
switch (kind) {
case "a":
runA();
break;
default:
throw new Error(`Unhandled kind: ${kind}`);
}
// ✅ valid
ESLint flat config example
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/default-case": "error",
},
},
];
When not to use it
Disable this rule if you enforce exhaustive unions with explicit never
checks and intentionally avoid default branches.
Package documentation
Rule catalog ID: R011
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.