Skip to content

Commit

Permalink
Chore: ignoring async generator function by default
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Mar 15, 2020
1 parent f1525dc commit 7bc8bc0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/rules/require-await.md
Expand Up @@ -18,6 +18,7 @@ async function fetchData(processDataItem) {

Asynchronous functions that don't use `await` might not need to be asynchronous functions and could be the unintentional result of refactoring.

> This rule doesnt report for non `await` async generator functions
## Rule Details

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-await.js
Expand Up @@ -68,7 +68,7 @@ module.exports = {
* @returns {void}
*/
function exitFunction(node) {
if (node.async && !scopeInfo.hasAwait && !astUtils.isEmptyFunction(node)) {
if (!node.generator && node.async && !scopeInfo.hasAwait && !astUtils.isEmptyFunction(node)) {
context.report({
node,
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/require-await.js
Expand Up @@ -55,6 +55,19 @@ ruleTester.run("require-await", rule, {
}
`,
parser: require.resolve("../../fixtures/parsers/typescript-parsers/global-for-await-of")
},
{
code: "async function* run() { anotherAsyncGenerator() }",
parserOptions: { ecmaVersion: 9 }
},
{
code: `async function* run() {
await new Promise(resolve => setTimeout(resolve, 100));
yield 'Hello';
console.log('World');
}
`,
parserOptions: { ecmaVersion: 9 }
}
],
invalid: [
Expand Down

0 comments on commit 7bc8bc0

Please sign in to comment.