From 7d56fea2213bee4d446c64e224b47dd93e0c86f4 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 5 Sep 2020 20:03:04 +0200 Subject: [PATCH 1/2] 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 From a558c381031e07e36b2542d2f5d7f12efe697ea7 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sat, 5 Sep 2020 21:00:03 +0200 Subject: [PATCH 2/2] Revert order of examples --- docs/rules/no-return-await.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/rules/no-return-await.md b/docs/rules/no-return-await.md index 13723a39218..e3f7be259d7 100644 --- a/docs/rules/no-return-await.md +++ b/docs/rules/no-return-await.md @@ -32,18 +32,18 @@ async function foo() { return; } +// 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; +} + // 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) {} } - -// 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