Skip to content

unicorn/no-useless-switch-case Pedantic

🚧 An auto-fix is still under development.

What it does

Disallows useless default cases in switch statements.

Why is this bad?

An empty case before the last default case is useless.

Examples

Examples of incorrect code for this rule:

javascript
switch (foo) {
  case 1:
  default:
    handleDefaultCase();
    break;
}

Examples of correct code for this rule:

javascript
switch (foo) {
  case 1:
  case 2:
    handleCase1And2();
    break;
}

References

Released under the MIT License.