# no-useless-recursion

Rule `unicorn/no-useless-recursion`. Disallow simple recursive function calls that can be replaced with a loop.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1025 by reach, #1280 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-useless-recursion` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-useless-recursion.md) |
| Biome | `nursery/noUselessRecursion` | no | no | group nursery, since 2.6.4 | [docs](https://biomejs.dev/linter/rules/no-useless-recursion/) |

## Code examples

### Incorrect: the rule reports this

```js
function foo(bar) {
  if (bar.baz) {
    return foo(bar.baz);
  }

  return bar;
}
```

### Correct: the rule accepts this

```js
function foo(bar) {
  while (bar.baz) {
    bar = bar.baz;
  }

  return bar;
}
```

```js
function foo(bar) {
  if (Array.isArray(bar)) {
    return bar.map(baz => foo(baz));
  }

  return bar;
}
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-useless-recursion": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noUselessRecursion": "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/no-mismatched-map-key](https://lintradar.dev/rules/unicorn/no-mismatched-map-key.md): Disallow checking a Map key before accessing a different key.
- [unicorn/prefer-continue](https://lintradar.dev/rules/unicorn/prefer-continue.md): Prefer early continues over conditionals wrapping the remainder of the loop body.
- [unicorn/no-for-loop](https://lintradar.dev/rules/unicorn/no-for-loop.md): Do not use a `for` loop that can be replaced with a `for-of` loop.
- [unicorn/prefer-else-if](https://lintradar.dev/rules/unicorn/prefer-else-if.md): Prefer `else if` over adjacent `if` statements with related conditions.
- [unicorn/no-duplicate-if-branches](https://lintradar.dev/rules/unicorn/no-duplicate-if-branches.md): Disallow duplicate adjacent branches in if chains.
- [unicorn/prefer-iterator-zip](https://lintradar.dev/rules/unicorn/prefer-iterator-zip.md): Prefer `Iterator.zip()` over parallel-array indexing.

---

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