跳转到内容

noEmptyBlockStatements

此内容尚不支持你的语言。

Diagnostic Category: lint/suspicious/noEmptyBlockStatements

Since: v1.3.0 Sources:

Disallow empty block statements and static blocks.

Empty static blocks and block statements, while not technically errors, usually occur due to refactoring that wasn’t completed. They can cause confusion when reading code.

This rule disallows empty block statements and static blocks. This rule ignores block statements or static blocks which contain a comment (for example, in an empty catch or finally block of a try statement to indicate that execution should continue regardless of errors).

function emptyFunctionBody () {}
code-block.js:1:31 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty block.

> 1 │ function emptyFunctionBody () {}
^^
2 │

Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.

try {
doSomething();
} catch(ex) {
}
code-block.js:3:13 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty block.

1 │ try {
2 │ doSomething();
> 3 │ } catch(ex) {
^
> 4 │
> 5 │ }
^
6 │

Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.

class Foo {
static {}
}
code-block.js:2:3 lint/suspicious/noEmptyBlockStatements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected empty block.

1 │ class Foo {
> 2 │ static {}
^^^^^^^^^
3 │ }
4 │

Empty blocks are usually the result of an incomplete refactoring. Remove the empty block or add a comment inside it if it is intentional.

function foo () {
doSomething();
}
try {
doSomething();
} catch (ex) {
// continue regardless of error
}