An empty code block is confusing. It will require some effort from maintainers to determine if it is intentional or indicates the implementation is
incomplete.
func compute(a int, b int) {
sum := a + b
if sum > 0 { } // Noncompliant; empty on purpose or missing piece of code?
fmt.Println("Result:", sum)
}
Removing or filling the empty code blocks takes away ambiguity and generally results in a more straightforward and less surprising code.
Exceptions
The rule ignores:
- code blocks that contain comments.
-
for
without init
and post
statements with empty blocks