close

no-empty-function

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-empty-function': 'error',
    },
  },
]);

Rule Details

Disallow empty functions. Empty functions can hide incomplete refactors; add a comment to intentionally empty function bodies, or configure an allowed function kind.

Examples of incorrect code for this rule:

function noop() {}

const handler = () => {};

class Service {
  connect() {}
}

Examples of correct code for this rule:

function noop() {
  // intentionally empty
}

const handler = () => value;

class Service {
  connect() {
    start();
  }
}

TypeScript parameter-property constructors are also allowed:

class Store {
  constructor(private readonly id: string) {}
}

Options

  • allow: An array of empty function kinds to permit. Default: [].

Allowed values:

  • functions
  • arrowFunctions
  • generatorFunctions
  • methods
  • generatorMethods
  • getters
  • setters
  • constructors
  • asyncFunctions
  • asyncMethods
  • privateConstructors
  • protectedConstructors
  • decoratedFunctions
  • overrideMethods

Examples of correct code for this rule with { "allow": ["constructors"] }:

{ "no-empty-function": ["error", { "allow": ["constructors"] }] }
class Service {
  constructor() {}
}

Examples of correct code for this rule with { "allow": ["decoratedFunctions"] }:

{ "no-empty-function": ["error", { "allow": ["decoratedFunctions"] }] }
class Service {
  @bound
  handle() {}
}

Original Documentation