# isolated-functions

Rule `unicorn/isolated-functions`. Prevent usage of variables from outside the scope of isolated functions.

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

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/isolated-functions` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/isolated-functions.md) |
| Biome | `nursery/noOuterScopeInIsolatedFunctions` | no | no | group nursery, since 2.6.10 | [docs](https://biomejs.dev/linter/rules/no-outer-scope-in-isolated-functions/) |

## Code examples

### Incorrect: the rule reports this

```js
const getText = makeSynchronous(async () => {
  const response = await fetch(url); // ❌ 'url' is not defined in isolated function scope
  return response.text();
});
```

```js
/** @isolated */
function abc() {
  return foo.slice(); // ❌ 'foo' is not defined in isolated function scope
}

const object = {
  /** @isolated */
  method() {
    return this.foo; // ❌ 'this' depends on external object state
  },
};
```

### Correct: the rule accepts this

```js
const getText = makeSynchronous(async () => {
  const url = 'https://example.com'; // Variable defined within function scope
  const response = await fetch(url);
  return response.text();
});
```

```js
const getText = makeSynchronous(async (url) => { // Variable passed as parameter
  const response = await fetch(url);
  return response.text();
});

console.log(getText('https://example.com'));
```

```js
/** @isolated */
function abc() {
  const foo = 'hi'; // Variable defined within function scope
  return foo.slice();
}
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/isolated-functions": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noOuterScopeInIsolatedFunctions": "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/default-export-style](https://lintradar.dev/rules/unicorn/default-export-style.md): Enforce consistent default export declarations.
- [unicorn/no-break-in-nested-loop](https://lintradar.dev/rules/unicorn/no-break-in-nested-loop.md): Disallow `break` and optionally `continue` in nested loops and switches inside loops.
- [unicorn/consistent-tuple-labels](https://lintradar.dev/rules/unicorn/consistent-tuple-labels.md): Enforce consistent labels on tuple type elements.
- [unicorn/no-duplicate-if-branches](https://lintradar.dev/rules/unicorn/no-duplicate-if-branches.md): Disallow duplicate adjacent branches in if chains.
- [unicorn/consistent-json-file-read](https://lintradar.dev/rules/unicorn/consistent-json-file-read.md): Enforce consistent JSON file reads before `JSON.parse()`.
- [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.

---

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