@typescript-eslint/eslint-plugin
Version:
TypeScript plugin for ESLint
87 lines (64 loc) • 2.23 kB
Markdown
---
description: 'Disallow empty functions.'
---
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-empty-function** for documentation.
This rule extends the base [`eslint/no-empty-function`](https://eslint.org/docs/rules/no-empty-function) rule.
It adds support for handling TypeScript specific code that would otherwise trigger the rule.
One example of valid TypeScript specific code that would otherwise trigger the `no-empty-function` rule is the use of [parameter properties](https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties) in constructor functions.
This rule adds the following options:
```ts
type AdditionalAllowOptionEntries =
| 'private-constructors'
| 'protected-constructors'
| 'decoratedFunctions'
| 'overrideMethods';
type AllowOptionEntries =
| BaseNoEmptyFunctionAllowOptionEntries
| AdditionalAllowOptionEntries;
interface Options extends BaseNoEmptyFunctionOptions {
allow?: Array<AllowOptionEntries>;
}
const defaultOptions: Options = {
...baseNoEmptyFunctionDefaultOptions,
allow: [],
};
```
Examples of correct code for the `{ "allow": ["private-constructors"] }` option:
```ts option='{ "allow": ["private-constructors"] }' showPlaygroundButton
class Foo {
private constructor() {}
}
```
Examples of correct code for the `{ "allow": ["protected-constructors"] }` option:
```ts option='{ "allow": ["protected-constructors"] }' showPlaygroundButton
class Foo {
protected constructor() {}
}
```
Examples of correct code for the `{ "allow": ["decoratedFunctions"] }` option:
```ts option='{ "allow": ["decoratedFunctions"] }' showPlaygroundButton
@decorator()
function foo() {}
class Foo {
@decorator()
foo() {}
}
```
Examples of correct code for the `{ "allow": ["overrideMethods"] }` option:
```ts option='{ "allow": ["overrideMethods"] }' showPlaygroundButton
abstract class Base {
protected greet(): void {
console.log('Hello!');
}
}
class Foo extends Base {
protected override greet(): void {}
}
```