Skip to main content

default-case

Require a default branch in switch statements.

Deprecated

  • Lifecycle: Deprecated, frozen, and non-recommended.
  • Deprecated since: v3.0.0
  • Available until: v4.0.0
  • Use instead: ESLint core default-case

This rule is a direct runtime proxy of the core rule and adds no independent analysis. Migrate the options unchanged to the core rule ID.

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: R013

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.