# prefer-abort-signal-timeout

Rule `unicorn/prefer-abort-signal-timeout`. Prefer `AbortSignal.timeout()` over manually aborting an `AbortController` with `setTimeout()`.

- 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: #1059 by reach, #1314 by growth

## Linters

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

## Code examples

### Incorrect: the rule reports this

```js
const abortController = new AbortController();
setTimeout(() => abortController.abort(), 1000);

await fetch(url, {signal: abortController.signal});
```

### Correct: the rule accepts this

```js
const abortSignal = AbortSignal.timeout(1000);

await fetch(url, {signal: abortSignal});
```

```js
const abortController = new AbortController();
setTimeout(() => abortController.abort(), 1000);
button.addEventListener('click', () => abortController.abort());

await fetch(url, {signal: abortController.signal});
```

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-abort-signal-timeout": "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-abort-signal-any](https://lintradar.dev/rules/unicorn/prefer-abort-signal-any.md): Prefer `AbortSignal.any()` over manually forwarding abort events between signals.
- [unicorn/prefer-array-from-async](https://lintradar.dev/rules/unicorn/prefer-array-from-async.md): Prefer `Array.fromAsync()` over array accumulation loops.
- [unicorn/operator-assignment](https://lintradar.dev/rules/unicorn/operator-assignment.md): Require assignment operator shorthand where possible.
- [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/no-useless-else](https://lintradar.dev/rules/unicorn/no-useless-else.md): Disallow `else` after a statement that exits.
- [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.

---

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