> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-lone-blocks

[Added in v0.5.0](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.0)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-lone-blocks': 'error',
    },
  },
]);
```

## Rule Details

This rule disallows nested (non-function) lone blocks. A lone block is a block that is not part of an `if`, `for`, `while`, `function`, `try`, class static block, or other statement that naturally introduces one. In ES6+, a block can be useful to scope `let`, `const`, `class`, `function`, or `using` declarations — this rule only flags blocks that do not contain such block-scoped bindings.

Examples of **incorrect** code for this rule:

```javascript
{}

{
  var x = 1;
}

if (foo) {
  bar();
  {
    baz();
  }
}

function foo() {
  {
    var x = 1;
  }
}

class C {
  static {
    {
      foo();
    }
  }
}
```

Examples of **correct** code for this rule:

```javascript
while (foo) {
  bar();
}

if (foo) {
  if (bar) {
    baz();
  }
}

{
  let x = 1;
}

{
  const y = 2;
}

{
  class Bar {}
}

switch (foo) {
  case bar: {
    baz();
  }
}

class C {
  static {
    foo();
  }
}
```

## Original Documentation

- [ESLint: no-lone-blocks](https://eslint.org/docs/latest/rules/no-lone-blocks)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-lone-blocks.js)
