# no-dupe-else-if

> Disallow an `else if` with a condition that an earlier branch already covers

In an `if ... else if` chain, a branch only runs if every condition before it was false. If a condition repeats an earlier one, its branch can never run. It's usually a copied line where someone forgot to change the condition.

The rule also understands `||` and `&&`. After `if (a || b)`, both `else if (a)` and `else if (b && c)` are dead. The order of the operands doesn't matter.

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-dupe-else-if" = "off" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
if (status === "active") {
  enable();
} else if (status === "paused") {
  pause();
} else if (status === "active") {
  archive();
}
```

Not reported:

{/* good */}
```js
if (status === "active") {
  enable();
} else if (status === "paused") {
  pause();
} else if (status === "archived") {
  archive();
}
```

A condition that's narrower than an earlier one is reported too:

{/* bad {"count": 2} */}
```js
if (user.isAdmin || user.isOwner) {
  showAll();
} else if (user.isOwner && user.isVerified) {
  showMost();
} else if (user.isAdmin) {
  showSome();
}
```

Put the narrower condition first:

{/* good */}
```js
if (user.isOwner && user.isVerified) {
  showMost();
} else if (user.isAdmin || user.isOwner) {
  showAll();
}
```
