Skip to content

eslint/no-empty-function Restriction

What it does

Disallows the usages of empty functions

Why is this bad?

Empty functions can reduce readability because readers need to guess whether it’s intentional or not. So writing a clear comment for empty functions is a good practice.

Example

Examples of incorrect code for this rule:

javascript
function foo() {}

const bar = () => {};

Examples of correct code for this rule:

javascript
function foo() {
  // do nothing
}

function foo() {
  return;
}
const add = (a, b) => a + b;

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-empty-function
json
{
  "rules": {
    "no-empty-function": "error"
  }
}

References

Released under the MIT License.