# unicorn/no-useless-switch-case

> Disallow empty `case` clauses that fall through to the last `default`

An empty `case` right before a final `default` runs the same code as `default`. The value gets there anyway, so the `case` does nothing.

`--fix-suggestions` removes the `case`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-useless-switch-case" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
switch (status) {
  case "active":
    show(user);
    break;
  case "banned":
  default:
    hide(user);
}
```

Not reported:

{/* good */}
```js
switch (status) {
  case "active":
    show(user);
    break;
  default:
    hide(user);
}
```

A `case` with its own code is fine, even if it falls through. So are empty cases that share code with another `case`:

{/* good */}
```js
switch (status) {
  case "banned":
    log(user);
  default:
    hide(user);
}

switch (status) {
  case "banned":
  case "deleted":
    hide(user);
}
```

## When not to use it

Listing a value next to `default` can show that you thought of it. If you write cases like that on purpose, turn the rule off.
