noEmptyBlockStatements
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/suspicious/noEmptyBlockStatements
Since: v1.3.0
Sources:
- Same as:
no-empty
- Same as:
no-empty-static-block
- Same as:
no-empty-function
- Same as:
@typescript-eslint/no-empty-function
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).
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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.
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.
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.