no-empty-function.md
2.09 KB
no-empty-function
)
Disallow empty functions (Rule Details
This rule extends the base eslint/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 in constructor functions.
How to use
{
// 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.
This rule adds the following options:
type AdditionalAllowOptionEntries =
| 'private-constructors'
| 'protected-constructors'
| 'decoratedFunctions';
type AllowOptionEntries =
| BaseNoEmptyFunctionAllowOptionEntries
| AdditionalAllowOptionEntries;
interface Options extends BaseNoEmptyFunctionOptions {
allow?: Array<AllowOptionEntries>;
}
const defaultOptions: Options = {
...baseNoEmptyFunctionDefaultOptions,
allow: [],
};
private-constructors
allow: Examples of correct code for the { "allow": ["private-constructors"] }
option:
class Foo {
private constructor() {}
}
protected-constructors
allow: Examples of correct code for the { "allow": ["protected-constructors"] }
option:
class Foo {
protected constructor() {}
}
decoratedFunctions
allow: Examples of correct code for the { "allow": ["decoratedFunctions"] }
option:
@decorator()
function foo() {}
class Foo {
@decorator()
foo() {}
}
How to use
{
// note you must disable the base rule as it can report incorrect errors
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error"]
}
Taken with ❤️ from ESLint core