# no-empty

Disallow empty block statements.

Block statements with nothing in them are very common when refactoring, however they can get confusing really quickly. This rule reports empty block statements and empty switch case blocks if they do not have a comment.

# Invalid Code Examples

{}
if (foo) {

}

# Correct Code Examples

if (foo) {
    /* todo */
}

# Config

Name Type Description
disallowEmptyFunctions bool Whether to disallow empty block statements in function declarations, arrow functions,
getters, setters, and methods.
allowEmptyCatch bool Whether to allow empty catch clauses without a comment.
More incorrect examples
{}
if (foo) {}
do { } while (scoot)
for(let i = 5; i < 10; i++) {}
switch (foo) {}
switch (foo /* bar */) {}
More correct examples
{ /* sike you thought it was empty */ }
{
// foo   
}
if (foo) { /* */ }
switch (bar) { /* */ }

Source (opens new window)

Last Updated: 11/18/2020, 9:36:33 PM