# no-all-duplicated-branches

Rule `sonarjs/no-all-duplicated-branches`. All branches in a conditional structure should not have exactly the same implementation

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1238 by reach, #539 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-all-duplicated-branches` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3923/) |

## Code examples

### Incorrect: the rule reports this

```js
if (b == 0) {  // Noncompliant
  doOneMoreThing();
}
else {
  doOneMoreThing();
}

let a = (b == 0) ? getValue() : getValue();   // Noncompliant

switch (i) {  // Noncompliant
  case 1:
    doSomething();
    break;
  case 2:
    doSomething();
    break;
  case 3:
    doSomething();
    break;
  default:
    doSomething();
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-all-duplicated-branches": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/new-operator-misuse](https://lintradar.dev/rules/sonarjs/new-operator-misuse.md): "new" should only be used with functions and classes
- [sonarjs/no-alphabetical-sort](https://lintradar.dev/rules/sonarjs/no-alphabetical-sort.md): "Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function
- [sonarjs/misplaced-loop-counter](https://lintradar.dev/rules/sonarjs/misplaced-loop-counter.md): "for" loop increment clauses should modify the loops' counters
- [sonarjs/no-angular-bypass-sanitization](https://lintradar.dev/rules/sonarjs/no-angular-bypass-sanitization.md): Angular built-in sanitization should not be disabled
- [sonarjs/memoize-cache-key](https://lintradar.dev/rules/sonarjs/memoize-cache-key.md): Lodash and Underscore.js `memoize` calls on functions with multiple parameters should use an explicit cache key function
- [sonarjs/no-array-delete](https://lintradar.dev/rules/sonarjs/no-array-delete.md): "delete" should not be used on arrays

---

Web page: https://lintradar.dev/rules/sonarjs/no-all-duplicated-branches. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
