Urara-Blog/node_modules/.pnpm-store/v3/files/af/47c4b6cff7d535bd03efa2125a275dd0203885f1c7c15911253fd47a2c33bcdcd8685fb62e9f14166bfdcf53b39d5b6d95dbcfcd5111ffab401457157431c5
2022-08-14 01:14:53 +08:00

115 lines
2.5 KiB
Text

---
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.
## Rule Details
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.
## How to Use
```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error"]
}
```
## Options
See [`eslint/no-empty-function` options](https://eslint.org/docs/rules/no-empty-function#options).
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: [],
};
```
### allow: `private-constructors`
Examples of correct code for the `{ "allow": ["private-constructors"] }` option:
```ts
class Foo {
private constructor() {}
}
```
### allow: `protected-constructors`
Examples of correct code for the `{ "allow": ["protected-constructors"] }` option:
```ts
class Foo {
protected constructor() {}
}
```
### allow: `decoratedFunctions`
Examples of correct code for the `{ "allow": ["decoratedFunctions"] }` option:
```ts
@decorator()
function foo() {}
class Foo {
@decorator()
foo() {}
}
```
### allow: `overrideMethods`
Examples of correct code for the `{ "allow": ["overrideMethods"] }` option:
```ts
abstract class Base {
protected greet(): void {
console.log('Hello!');
}
}
class Foo extends Base {
protected override greet(): void {}
}
```
## How to Use
```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error"]
}
```
<sup>
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-empty-function.md)
</sup>