# prefer-combined-guards

Rule `unicorn/prefer-combined-guards`. Prefer combining consecutive guards with identical exit statements.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1063 by reach, #1318 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-combined-guards` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-combined-guards.md) |

## Code examples

### Incorrect: the rule reports this

```js
function check(context) {
  if (context.finished) {
    return;
  }

  if (context.cancelled) {
    return;
  }
}
```

```js
function validate(value) {
  if (value < 0) {
    throw invalidValue;
  }

  if (!Number.isFinite(value)) {
    throw invalidValue;
  }
}
```

```js
for (const item of items) {
  if (item.hidden) {
    continue;
  }

  if (item.disabled) {
    continue;
  }

  processItem(item);
}
```

### Correct: the rule accepts this

```js
function check(context) {
  if (context.finished || context.cancelled) {
    return;
  }
}
```

```js
function validate(value) {
  if ((value < 0) || !Number.isFinite(value)) {
    throw invalidValue;
  }
}
```

```js
for (const item of items) {
  if (item.hidden || item.disabled) {
    continue;
  }

  processItem(item);
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-combined-guards": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-array-slice](https://lintradar.dev/rules/unicorn/prefer-array-slice.md): Prefer `Array#slice()` over `Array#splice()` when reading from the returned array.
- [unicorn/prefer-dom-node-html-methods](https://lintradar.dev/rules/unicorn/prefer-dom-node-html-methods.md): Prefer `.getHTML()` and `.setHTML()` over `.innerHTML`.
- [unicorn/prefer-array-iterable-methods](https://lintradar.dev/rules/unicorn/prefer-array-iterable-methods.md): Prefer iterating an array directly or with `Array#keys()` over `Array#entries()` when the index or value is unused.
- [unicorn/prefer-get-or-insert-computed](https://lintradar.dev/rules/unicorn/prefer-get-or-insert-computed.md): Prefer `.getOrInsertComputed()` when the default value has side effects.
- [unicorn/prefer-array-from-async](https://lintradar.dev/rules/unicorn/prefer-array-from-async.md): Prefer `Array.fromAsync()` over array accumulation loops.
- [unicorn/prefer-group-by](https://lintradar.dev/rules/unicorn/prefer-group-by.md): Prefer `Object.groupBy()` or `Map.groupBy()` over manual grouping.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-combined-guards. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
