close

no-useless-switch-case

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-useless-switch-case': 'error',
    },
  },
]);

Rule Details

Disallows empty case clauses immediately before the final default clause in a switch statement.

An empty case before the last default case is useless because execution falls through to the same default body. Empty blocks and empty statements inside that case still count as empty.

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

switch (foo) {
  default:
    handleDefaultCase();
    break;
}
switch (foo) {
  case 1:
  case 2:
    handleCase1And2();
    break;
}
switch (foo) {
  case 1:
    handleCase1();
  default:
    handleDefaultCase();
    break;
}

Original Documentation