Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: added async in allow method in no-empty-function (fixes #12768) #13036

Merged
merged 8 commits into from Mar 20, 2020
31 changes: 31 additions & 0 deletions docs/rules/no-empty-function.md
Expand Up @@ -177,6 +177,8 @@ This rule has an option to allow specific kinds of functions to be empty.
* `"getters"` - Getters.
* `"setters"` - Setters.
* `"constructors"` - Class constructors.
* `"asyncFunctions"` - Async Functions.
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
* `"asyncMethods"` - Class methods and method shorthands of object literals with async
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved

#### allow: functions

Expand Down Expand Up @@ -307,6 +309,35 @@ class A {
}
```

#### allow: asyncFunctions

Examples of **correct** code for `{ "allow": ["asyncFunctions"] }` options:
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved

```js
/*eslint no-empty-function: ["error", { "allow": ["asyncFunctions"] }]*/
/*eslint-env es6*/
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved

async function a(){}
```

#### allow: asyncMethods

Examples of **correct** code for `{ "allow": ["asyncMethods"] }` options:
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved

```js
/*eslint no-empty-function: ["error", { "allow": ["asyncMethods"] }]*/
/*eslint-env es6*/

var obj = {
async foo() {}
};

class A {
async foo() {}
static async foo() {}
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
}
```

## When Not To Use It

If you don't want to be notified about empty functions, then it's safe to disable this rule.
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-empty-function.js
Expand Up @@ -23,7 +23,9 @@ const ALLOW_OPTIONS = Object.freeze([
"generatorMethods",
"getters",
"setters",
"constructors"
"constructors",
"asyncFunctions",
"asyncMethods"
]);

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/lib/rules/no-empty-function.js
Expand Up @@ -24,7 +24,9 @@ const ALLOW_OPTIONS = Object.freeze([
"generatorMethods",
"getters",
"setters",
"constructors"
"constructors",
"asyncFunctions",
"asyncMethods"
]);

/**
Expand Down Expand Up @@ -267,6 +269,16 @@ ruleTester.run("no-empty-function", rule, [
{
code: "var foo = () => 0;",
parserOptions: { ecmaVersion: 6 }
},
{
code: "const foo = { async method() {} }",
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
options: [{ allow: ["asyncMethods"] }],
parserOptions: { ecmaVersion: 8 }
},
{
code: "async function a(){}",
options: [{ allow: ["asyncFunctions"] }],
parserOptions: { ecmaVersion: 8 }
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
}
],
invalid: []
Expand Down