# @typescript-eslint/no-empty-function

> Disallow functions with an empty body

An empty function is either unfinished or does nothing on purpose, and the reader can't tell which. If it's on purpose, say so in a comment in the body. A function with a comment in it isn't reported.

A constructor that declares properties in its parameters, such as `constructor(private name: string) {}`, isn't reported either.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-empty-function" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-empty-function" = ["error", {
  allow = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
function onClose() {}

class Logger {
  flush() {}
}
```

Not reported:

{/* good */}
```ts
function onClose() {
  // Nothing to clean up.
}

class Logger {
  constructor(private prefix: string) {}

  flush() {
    console.log(this.prefix);
  }
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allow` | `[]` | The kinds of functions that may be empty. |

| In `allow` | What may be empty |
| --- | --- |
| `"functions"` | `function save() {}` and `function () {}` |
| `"arrowFunctions"` | `() => {}` and `async () => {}` |
| `"generatorFunctions"` | `function* items() {}` |
| `"asyncFunctions"` | `async function load() {}` |
| `"methods"` | `flush() {}` in a class or an object |
| `"generatorMethods"` | `*items() {}` |
| `"asyncMethods"` | `async load() {}` |
| `"getters"` | `get size() {}` |
| `"setters"` | `set size(value) {}` |
| `"constructors"` | Every constructor |
| `"private-constructors"` | `private constructor() {}` |
| `"protected-constructors"` | `protected constructor() {}` |
| `"decoratedFunctions"` | Methods that have a decorator |
| `"overrideMethods"` | Methods marked `override` |

An empty arrow function is a common way to write "do nothing":

{/* good {"options": [{"allow": ["arrowFunctions"]}]} */}
```ts
const noop = () => {};
const wait = async () => {};
```

A private constructor stops other code from calling `new`:

{/* good {"options": [{"allow": ["private-constructors"]}]} */}
```ts
class Registry {
  static shared = new Registry();

  private constructor() {}
}
```

An `override` with an empty body turns off what the base class does:

{/* good {"options": [{"allow": ["overrideMethods"]}]} */}
```ts
class Widget {
  render() {
    console.log("widget");
  }
}

class Spacer extends Widget {
  override render() {}
}
```
