Skip to content

Commit

Permalink
Docs: clarify correct example in no-return-await (fixes #13656)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Sep 5, 2020
1 parent bf2e367 commit 7d56fea
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions docs/rules/no-return-await.md
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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

Expand Down

0 comments on commit 7d56fea

Please sign in to comment.