# no-inner-declarations

Rule `eslint/no-inner-declarations`. Disallow variable or `function` declarations in nested blocks

- Source: eslint
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 40.9M weekly downloads of presets that enable it
- Trend: +65.2% last quarter
- Rank: #414 by reach, #456 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-inner-declarations` | no | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-inner-declarations) |
| Oxlint | `no-inner-declarations` | no | no | plugin `eslint`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-inner-declarations.html) |
| Biome | `correctness/noInnerDeclarations` | yes | no | group correctness, since 1.0.0 | [docs](https://biomejs.dev/linter/rules/no-inner-declarations/) |

## Code examples

### Incorrect: the rule reports this

```js
// script, non-strict code

if (test) {
    function doSomething() { }
}

function doSomethingElse() {
    if (test) {
        function doAnotherThing() { }
    }
}

if (foo) function f(){}
```

```js
if (test) {
    var foo = 42;
}

function doAnotherThing() {
    if (test) {
        var bar = 81;
    }
}

if (foo) var a;

if (foo) function f(){}

class C {
    static {
        if (test) {
            var something;
        }
    }
}
```

```js
// non-strict code

if (test) {
    function doSomething() { }
}

function doSomething() {
    if (test) {
        function doSomethingElse() { }
    }
}

// strict code

function foo() {
    "use strict";

    if (test) {
        function bar() { }
    }
}
```

### Correct: the rule accepts this

```js
function doSomething() { }

function doSomethingElse() {
    function doAnotherThing() { }
}

function doSomethingElse() {
    "use strict";

    if (test) {
        function doAnotherThing() { }
    }
}

class C {
    static {
        function doSomething() { }
    }
}

if (test) {
    asyncCall(id, function (err, data) { });
}

var fn;
if (test) {
    fn = function fnExpression() { };
}

if (foo) var a;
```

```js
var bar = 42;

if (test) {
    let baz = 43;
}

function doAnotherThing() {
    var baz = 81;
}

class C {
    static {
        var something;
    }
}
```

```js
function doSomething() { }

function doSomething() {
    function doSomethingElse() { }
}
```

Examples from the ESLint documentation.

## Enable it

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "no-inner-declarations": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "correctness": {
        "noInnerDeclarations": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [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% |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [eslint/prefer-numeric-literals](https://lintradar.dev/rules/eslint/prefer-numeric-literals.md): Disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals
- [eslint/no-constructor-return](https://lintradar.dev/rules/eslint/no-constructor-return.md): Disallow returning value from constructor
- [eslint/prefer-template](https://lintradar.dev/rules/eslint/prefer-template.md): Require template literals instead of string concatenation
- [eslint/prefer-exponentiation-operator](https://lintradar.dev/rules/eslint/prefer-exponentiation-operator.md): Disallow the use of `Math.pow` in favor of the `**` operator
- [eslint/radix](https://lintradar.dev/rules/eslint/radix.md): Enforce the use of the radix argument when using `parseInt()`
- [eslint/no-useless-call](https://lintradar.dev/rules/eslint/no-useless-call.md): Disallow unnecessary calls to `.call()` and `.apply()`

---

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