From a964dfaef7d75bbb2d644a16e4c7aecb6ed2fa4c Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Tue, 20 Feb 2018 01:51:20 -0500 Subject: [PATCH] Fix: ensure no-await-in-loop reports the correct node (fixes #9992) --- lib/rules/no-await-in-loop.js | 2 +- tests/lib/rules/no-await-in-loop.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-await-in-loop.js b/lib/rules/no-await-in-loop.js index d0a2a58935b..ef0bda90bf9 100644 --- a/lib/rules/no-await-in-loop.js +++ b/lib/rules/no-await-in-loop.js @@ -84,7 +84,7 @@ module.exports = { while (parent && !isBoundary(parent)) { if (isLooped(node, parent)) { context.report({ - node, + node: awaitNode, messageId: "unexpectedAwait" }); return; diff --git a/tests/lib/rules/no-await-in-loop.js b/tests/lib/rules/no-await-in-loop.js index 057223879ab..fcb6db061ee 100644 --- a/tests/lib/rules/no-await-in-loop.js +++ b/tests/lib/rules/no-await-in-loop.js @@ -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 } }); @@ -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] },