# branches-sharing-code

Rule `oxc/branches-sharing-code`. Checks if the `if` and `else` blocks contain shared code that can be moved out of the blocks.

- Source: oxc
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 2.1M weekly downloads of presets that enable it
- Trend: +151.7% last quarter
- Rank: #1518 by reach, #22 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Oxlint | `oxc/branches-sharing-code` | no | safe | plugin `oxc`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/oxc/branches-sharing-code.html) |
| Biome | `nursery/noSharedBranchCode` | no | no | group nursery, since 2.6.6 | [docs](https://biomejs.dev/linter/rules/no-shared-branch-code/) |

## Code examples

### Incorrect: the rule reports this

```js
if (condition) {
    console.log("Hello");
    return 13;
} else {
    console.log("Hello");
    return 42;
};

if (condition) {
    doSomething();
    cleanup();
} else {
    doSomethingElse();
    cleanup();
}
```

### Correct: the rule accepts this

```js
console.log("Hello");
if (condition) {
    return 13;
} else {
    return 42;
};

if (condition) {
    doSomething();
} else {
    doSomethingElse();
}
cleanup();
```

Examples from the Oxlint documentation.

## Enable it

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "oxc/branches-sharing-code": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noSharedBranchCode": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |

## Related rules

- [oxc/bad-bitwise-operator](https://lintradar.dev/rules/oxc/bad-bitwise-operator.md): This rule applies when bitwise operators are used where logical operators are expected.
- [oxc/approx-constant](https://lintradar.dev/rules/oxc/approx-constant.md): Disallows the use of approximate constants, instead preferring the use of the constants in the `Math` object.
- [oxc/misrefactored-assign-op](https://lintradar.dev/rules/oxc/misrefactored-assign-op.md): Https://rust-lang.github.io/rust-clippy/master/#/misrefactored_assign_op
- [oxc/no-accumulating-spread](https://lintradar.dev/rules/oxc/no-accumulating-spread.md): Prevents using object or array spreads on accumulators in `Array.prototype.reduce()` and in loops.
- [oxc/no-async-endpoint-handlers](https://lintradar.dev/rules/oxc/no-async-endpoint-handlers.md): Disallows the use of `async` functions as Express endpoint handlers.
- [oxc/no-barrel-file](https://lintradar.dev/rules/oxc/no-barrel-file.md): Disallow the use of barrel files where the file contains `export *` statements, and the total number of modules exceeds a threshold.

---

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