Why is this an issue?
Empty functions can be a sign of poor code quality and can make the code harder to read and maintain. It usually happens when a developer forgets
to add any statements to it, or when a function is no longer needed but is not removed from the codebase. In these cases when it is an unintentional
omission, it should be fixed to prevent an unexpected behavior in production.
function foo() { //Noncompliant: Function does not have any statement
}
Ensure that all functions contain meaningful statements. Otherwise, they should be removed.
function foo() {
do_something();
}
Throw an exception if it is done intentionally due to some functionality not being supported yet.
function foo() {
throw new Error("Not yet implemented");
}
Exceptions
- This rule does not apply to functions containing comments. The comment should explain the reason for the intention of the blank override.
function foo() {
// This is intentional
}
- This rule does not apply to function expressions and arrow functions as they can denote default values.
static defaultProps = {
listStyle: () => {}
};
- The rule allows for empty functions with a name starting with the prefix
on
like onClick
.
function onClick() {
}
Resources
Documentation