eslint-config-ts-lib
Version:
ts-lib-scripts创建的ts库项目使用的ESLint配置
99 lines (70 loc) • 2.5 kB
Markdown
> 来自 [plugin:@typescript-eslint/recommended](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin) 的规则。
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.
```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error"]
}
```
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";
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
class Foo {
private constructor() {}
}
```
Examples of correct code for the `{ "allow": ["protected-constructors"] }` option:
```ts
class Foo {
protected constructor() {}
}
```
Examples of correct code for the `{ "allow": ["decoratedFunctions"] }` option:
```ts
@decorator()
function foo() {}
class Foo {
@decorator()
foo() {}
}
```
```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/master/docs/rules/no-empty-function.md)</sup>
- [@typescript-eslint/no-empty-function 官方文档](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/docs/rules/no-empty-function.md)