# no-loop-func

Rule `eslint/no-loop-func`. Disallow function declarations that contain unsafe references inside loop statements

- Source: eslint
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: no
- Reach: 16.6M weekly downloads of presets that enable it
- Trend: +11.0% last quarter
- Rank: #669 by reach, #1458 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-loop-func` | no | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-loop-func) |
| Oxlint | `no-loop-func` | no | no | plugin `eslint`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-loop-func.html) |
| Biome | `suspicious/noLoopFunc` | no | no | group suspicious, since 2.4.13 | [docs](https://biomejs.dev/linter/rules/no-loop-func/) |

## Code examples

### Incorrect: the rule reports this

```js
var i = 0;
while(i < 5) {
    var a = function() { return i; };
    a();

    i++;
}

var i = 0;
do {
    function a() { return i; };
    a();

    i++
} while (i < 5);

let foo = 0;
for (let i = 0; i < 10; ++i) {
    //Bad, `foo` is not in the loop-block's scope and `foo` is modified in/after the loop
    setTimeout(() => console.log(foo));
    foo += 1;
}

for (let i = 0; i < 10; ++i) {
    //Bad, `foo` is not in the loop-block's scope and `foo` is modified in/after the loop
    setTimeout(() => console.log(foo));
}
foo = 100;

var arr = [];

for (var i = 0; i < 5; i++) {
// …
```

### Correct: the rule accepts this

```ts
type MyType = 1;
let someArray: MyType[] = [];
for (let i = 0; i < 10; i += 1) {
  someArray = someArray.filter((item: MyType) => !!item);
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "no-loop-func": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-loop-func": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "noLoopFunc": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Create React App](https://lintradar.dev/presets/react-app.md) | ESLint | `eslint-config-react-app` | 109 | 4.1M | +4.3% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [typescript/no-loop-func](https://lintradar.dev/rules/typescript/no-loop-func.md): Disallow function declarations that contain unsafe references inside loop statements
- [eslint/curly](https://lintradar.dev/rules/eslint/curly.md): Enforce consistent brace style for all control statements
- [eslint/no-useless-concat](https://lintradar.dev/rules/eslint/no-useless-concat.md): Disallow unnecessary concatenation of literals or template literals
- [eslint/strict](https://lintradar.dev/rules/eslint/strict.md): Require or disallow strict mode directives
- [eslint/no-restricted-properties](https://lintradar.dev/rules/eslint/no-restricted-properties.md): Disallow certain properties on certain objects
- [eslint/camelcase](https://lintradar.dev/rules/eslint/camelcase.md): Enforce camelcase naming convention

---

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