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: ensure no-await-in-loop reports the correct node (fixes #9992) #9993

Merged
merged 1 commit into from Feb 20, 2018
Merged
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/no-await-in-loop.js
Expand Up @@ -84,7 +84,7 @@ module.exports = {
while (parent && !isBoundary(parent)) {
if (isLooped(node, parent)) {
context.report({
node,
node: awaitNode,
messageId: "unexpectedAwait"
});
return;
Expand Down
7 changes: 5 additions & 2 deletions tests/lib/rules/no-await-in-loop.js
Expand Up @@ -8,7 +8,7 @@
const rule = require("../../../lib/rules/no-await-in-loop"),
RuleTester = require("../../../lib/testers/rule-tester");

const error = { messageId: "unexpectedAwait" };
const error = { messageId: "unexpectedAwait", type: "AwaitExpression" };

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });

Expand Down Expand Up @@ -46,7 +46,10 @@ ruleTester.run("no-await-in-loop", rule, {
// While loops
{ code: "async function foo() { while (baz) { await bar; } }", errors: [error] },
{ code: "async function foo() { while (await foo()) { } }", errors: [error] },
{ code: "async function foo() { while (baz) { for await (x of xs); } }", errors: [error] },
{
code: "async function foo() { while (baz) { for await (x of xs); } }",
errors: [Object.assign({}, error, { type: "ForOfStatement" })]
},

// For of loops
{ code: "async function foo() { for (var bar of baz) { await bar; } }", errors: [error] },
Expand Down