Why is this an issue?

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:

Exceptions

This does not raise an issue in the following cases:

static defaultProps = {
  listStyle: () => {}
};

function onClick() {
}

function myNoopFunction() {
}

class C {
  constructor() {}
}

How to fix it

Code examples

Noncompliant code example

function shouldNotBeEmpty() {  // Noncompliant - method is empty
}

function notImplemented() {  // Noncompliant - method is empty
}

function emptyOnPurpose() {  // Noncompliant - method is empty
}

Compliant solution

function shouldNotBeEmpty() {
  doSomething();
}

function notImplemented() {
  throw new Error("notImplemented() cannot be performed because ...");
}

function emptyOnPurpose() {
  // comment explaining why the method is empty
}

Resources

Documentation

Related rules