Empty Function Body
ID |
go.empty_function_body |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Go |
Tags |
dead-code, reliability |
Description
Reports a function or method whose body is a present-but-empty block ({ } containing no
statement, or a body holding only comments). An empty function silently does nothing while
looking like a real implementation; callers cannot tell that the operation is a no-op.
Rationale
A function with an empty body is almost always a sign of an incomplete change: a stub left
after a refactoring, a callback that was never wired up, or a function that should have been
deleted. Comments do not count as statements — a body that contains only a // TODO is still
empty and still misleading. Body-less declarations (interface method elements and forward
declarations) are not reported, since they have no block to fill.
func Start() { // OK — body has statements
initialize()
}
func Stop() { // FLAW — body is empty
}
func Reset() { // FLAW — only a comment, not a statement
// TODO: implement
}
Remediation
Decide whether the function should do something or be removed. If a deliberate no-op is
required (for example to satisfy an interface), document the intent with an executable
statement such as a log call or an explicit return, plus an explanatory comment.