Skip to main content

no-unnecessary-break

Disallow unnecessary trailing break statements in switch blocks.

Targeted pattern scopeโ€‹

This rule matches break statements that appear in the last case of a switch statement.

Specifically, it reports when the final SwitchCase ends with break;, because control flow would already exit the switch at that point.

What this rule reportsโ€‹

This rule reports a break statement when it appears in the last SwitchCase, where control would already exit the switch.

Why this rule existsโ€‹

A trailing break in the final case is dead control-flow noise. Removing it keeps switch blocks smaller and easier to scan.

โŒ Incorrectโ€‹

switch (x) {
case 1:
break;
case 2:
break;
}

โœ… Correctโ€‹

switch (x) {
case 1:
break;
case 2:
}

Behavior and migration notesโ€‹

This rule reports only and does not provide an autofix.

Manual migration is typically trivial: delete the final break; in the last case when no additional logic depends on it.

Optionsโ€‹

This rule has no options.

Additional examplesโ€‹

switch (status) {
case "ok":
handleOk();
break;
default:
handleDefault();
break; // โŒ unnecessary (last case)
}

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-unnecessary-break": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your team prefers explicit trailing break statements for style consistency.

Package documentationโ€‹

Rule catalog ID: R046

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.