From 7d56fea2213bee4d446c64e224b47dd93e0c86f4 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 5 Sep 2020 20:03:04 +0200 Subject: [PATCH] Docs: clarify correct example in no-return-await (fixes #13656) --- docs/rules/no-return-await.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/rules/no-return-await.md b/docs/rules/no-return-await.md index b1c60f092ae..13723a39218 100644 --- a/docs/rules/no-return-await.md +++ b/docs/rules/no-return-await.md @@ -11,6 +11,8 @@ This rule aims to prevent a likely common performance hazard due to a lack of un Examples of **incorrect** code for this rule: ```js +/*eslint no-return-await: "error"*/ + async function foo() { return await bar(); } @@ -19,6 +21,8 @@ async function foo() { Examples of **correct** code for this rule: ```js +/*eslint no-return-await: "error"*/ + async function foo() { return bar(); } @@ -28,19 +32,19 @@ async function foo() { return; } -async function foo() { - const x = await bar(); - return x; -} - +// In this example the `await` is necessary to be able to catch errors thrown from `bar()` async function foo() { try { return await bar(); } catch (error) {} } -``` -In the last example the `await` is necessary to be able to catch errors thrown from `bar()`. +// This is essentially the same as `return await bar();`, but the rule checks only `await` in `return` statements +async function foo() { + const x = await bar(); + return x; +} +``` ## When Not To Use It