Skip to content

unicorn/no-useless-switch-case Pedantic

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;
}

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-useless-switch-case": "error"
  }
}
bash
oxlint --deny unicorn/no-useless-switch-case

References