Skip to main content

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.