# no-empty

> Disallow empty block statements

An empty block is usually code that was never finished, or something a refactor left behind. An empty `catch` is worse, because the error disappears and nothing tells you that the call failed.

A block with a comment in it isn't reported, so you can say why it's empty. Empty function bodies aren't reported either. Use `no-empty-function` for those.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-empty" = "off" # or "error"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-empty" = ["warn", {
  allowEmptyCatch = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
try {
  cache.clear();
} catch (error) {}
```

{/* bad {"count": 2} */}
```js
if (user.active) {
}

switch (user.role) {
}
```

Not reported:

{/* good */}
```js
try {
  cache.clear();
} catch (error) {
  // The cache is optional. A failure here changes nothing.
}

function noop() {}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowEmptyCatch` | `false` | Allow an empty `catch` block. |

{/* good {"options": [{"allowEmptyCatch": true}]} */}
```js
try {
  cache.clear();
} catch (error) {}
```

Other empty blocks are still reported, including the `finally` of the same statement:

{/* bad {"options": [{"allowEmptyCatch": true}]} */}
```js
try {
  cache.clear();
} catch (error) {
} finally {
}
```
