# no-unenclosed-multiline-block

Rule `sonarjs/no-unenclosed-multiline-block`. Multiline blocks should be enclosed in curly braces

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1322 by reach, #623 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-unenclosed-multiline-block` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2681/) |

## Code examples

### Incorrect: the rule reports this

```js
if (condition)
  firstActionInBlock();
  secondAction();  // Noncompliant; executed unconditionally
thirdAction();

if (condition) firstActionInBlock(); secondAction();  // Noncompliant; secondAction executed unconditionally

if (condition) firstActionInBlock();  // Noncompliant
  secondAction();  // Executed unconditionally

if (condition); secondAction();  // Noncompliant; secondAction executed unconditionally

let str = undefined;
for (let i = 0; i < array.length; i++)
  str = array[i];
  doTheThing(str);  // Noncompliant; executed only on last array element
```

### Correct: the rule accepts this

```js
if (condition) {
  firstActionInBlock();
  secondAction();
}
thirdAction();

let str = undefined;
for (let i = 0; i < array.length; i++) {
  str = array[i];
  doTheThing(str);
}
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/no-unenclosed-multiline-block": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-undefined-argument](https://lintradar.dev/rules/sonarjs/no-undefined-argument.md): "undefined" should not be passed as the value of optional parameters
- [sonarjs/no-uniq-key](https://lintradar.dev/rules/sonarjs/no-uniq-key.md): JSX list components keys should match up between renders
- [sonarjs/no-try-promise](https://lintradar.dev/rules/sonarjs/no-try-promise.md): Promise rejections should not be caught by "try" blocks
- [sonarjs/no-unthrown-error](https://lintradar.dev/rules/sonarjs/no-unthrown-error.md): Errors should not be created without being thrown
- [sonarjs/no-trivial-assertions](https://lintradar.dev/rules/sonarjs/no-trivial-assertions.md): Assertions should not be trivially true
- [sonarjs/no-unused-collection](https://lintradar.dev/rules/sonarjs/no-unused-collection.md): Collection contents should be used

---

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