Empty if / else / catch / finally

ID

javascript.no_empty

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

JavaScript

Tags

dead-code, reliability

Description

Reports an empty block in a position that should contain real work — the body of an if / else branch, the body of a catch clause, or the body of a finally clause. An empty block in those positions almost always indicates a stub that was never filled in.

Empty function bodies are out of scope here — see javascript.empty_function_body. Empty loop bodies are out of scope — see javascript.empty_loop_body.

Rationale

  • An empty if body silently swallows the condition’s intent — a reader has to guess whether the developer meant to do nothing or forgot to write the work.

  • An empty catch swallows errors, the canonical anti-pattern: any exception in the try disappears.

  • An empty finally does nothing the engine wouldn’t already do; readers assume cleanup happens there.

// Bad
if (x > 0) {}
try {
  risky();
} catch (e) {}

Remediation

Either implement the body or remove the construct entirely.

// Good
if (x > 0) {
  handle(x);
}

try {
  risky();
} catch (e) {
  log.error(e);
}