An empty method is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty methods bring no functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.
There are several reasons for a method not to have a body:
This does not raise an issue in the following cases:
on like onClick. noop.
static defaultProps = {
listStyle: () => {}
};
function onClick() {
}
function myNoopFunction() {
}
class C {
constructor() {}
}
function shouldNotBeEmpty() { // Noncompliant - method is empty
}
function notImplemented() { // Noncompliant - method is empty
}
function emptyOnPurpose() { // Noncompliant - method is empty
}
function shouldNotBeEmpty() {
doSomething();
}
function notImplemented() {
throw new Error("notImplemented() cannot be performed because ...");
}
function emptyOnPurpose() {
// comment explaining why the method is empty
}