Skip to content

noEmptyBlockStatements (since v1.3.0)

Diagnostic Category: lint/suspicious/noEmptyBlockStatements

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 () {}
suspicious/noEmptyBlockStatements.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) {
}
suspicious/noEmptyBlockStatements.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 {}
}
suspicious/noEmptyBlockStatements.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
}