# no-duplicate-case

> Disallow two `case` labels with the same test in a `switch`

A `switch` runs the first `case` that matches. A second `case` with the same test is never chosen, so its code only runs if the case above it falls through. It's usually a copied `case` where someone forgot to change the label.

Two labels are the same if their source text is the same, ignoring whitespace and comments.

This rule is on by default.

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

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-duplicate-case" = "off" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
switch (event.key) {
  case "ArrowUp":
    moveUp();
    break;
  case "ArrowDown":
    moveDown();
    break;
  case "ArrowUp":
    selectPrevious();
    break;
}
```

Not reported:

{/* good */}
```js
switch (event.key) {
  case "ArrowUp":
    moveUp();
    break;
  case "ArrowDown":
    moveDown();
    break;
  case "PageUp":
    selectPrevious();
    break;
}
```

Labels don't have to be literals:

{/* bad */}
```js
switch (true) {
  case size > limit:
    reject();
    break;
  case size > limit:
    warn();
    break;
}
```
