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

Update: Disable require-await for async generators (fixes #12459) #12484

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/require-await.js
Expand Up @@ -64,7 +64,7 @@ module.exports = {
* @returns {void}
*/
function exitFunction(node) {
if (node.async && !scopeInfo.hasAwait && !astUtils.isEmptyFunction(node)) {
if (node.async && !node.generator && !scopeInfo.hasAwait && !astUtils.isEmptyFunction(node)) {
context.report({
node,
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/rules/require-await.js
Expand Up @@ -41,7 +41,11 @@ ruleTester.run("require-await", rule, {
"function foo() { doSomething() }",

// for-await-of
"async function foo() { for await (x of xs); }"
"async function foo() { for await (x of xs); }",

// async generators do not require await
"async function * bar () { yield * foo() }",
"async function * bar () { yield * await foo() }"
],
invalid: [
{
Expand Down Expand Up @@ -83,6 +87,10 @@ ruleTester.run("require-await", rule, {
{
code: "async function foo() { await async () => { doSomething() } }",
errors: ["Async arrow function has no 'await' expression."]
},
{
code: "async function foo () { baz() }",
errors: ["Async function 'foo' has no 'await' expression."]
}
]
});