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(eslint-plugin): [require-await] handle async generators #1782

Merged
merged 9 commits into from Mar 31, 2020
7 changes: 6 additions & 1 deletion packages/eslint-plugin/src/rules/require-await.ts
Expand Up @@ -62,7 +62,12 @@ export default util.createRule({
return;
}

if (node.async && !scopeInfo.hasAwait && !isEmptyFunction(node)) {
if (
!node.generator &&
node.async &&
!scopeInfo.hasAwait &&
!isEmptyFunction(node)
) {
context.report({
node,
loc: getFunctionHeadLoc(node, sourceCode),
Expand Down
19 changes: 19 additions & 0 deletions packages/eslint-plugin/tests/rules/require-await.test.ts
Expand Up @@ -104,6 +104,25 @@ async function testFunction(): Promise<void> {
))
}
`,
'async function* run() { yield * anotherAsyncGenerator() }',
`async function* foo() {
await Promise.resolve()
yield 1
}
async function* bar() {
yield* foo()
}`,
`
async function* run() {
await new Promise(resolve => setTimeout(resolve, 100));
yield 'Hello';
console.log('World');
}
`,
'async function* run() { }',
'const foo : () => void = async function *(){}',
'const foo = async function *(){ console.log("bar") }',
'async function* run() { console.log("bar") }',
],

invalid: [
Expand Down