Empty Function Body
ID |
javascript.empty_function_body |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
JavaScript |
Tags |
code-style, dead-code |
Description
Reports functions, function expressions, methods, generators, and arrow functions whose body is empty — a bare {} or only nested empty statements. Class constructors are out of scope: the javascript.no_useless_constructor rule covers those.
Rationale
An empty function body is almost always one of:
-
a stub that was never filled in,
-
a refactor leftover where the body was moved away,
-
an intentional no-op that lacks documentation.
Reviewers can’t tell which case applies. A short comment ("intentional no-op", "abstract method placeholder") lets future readers move on without investigating.
// Bad - looks unfinished
function processOrder(orderId) {}
const onClick = () => {};
class Service {
flush() {}
}
Remediation
Either implement the body, or document the intent clearly so a reviewer can tell deliberate no-ops from leftover stubs.
// Good
function processOrder(orderId) {
return orderRepository.find(orderId);
}
const onClick = () => {
// intentional no-op: third-party library requires a callback
};