Skip to content

Commit

Permalink
Docs: Updated no-return-await Rule Documentation (fixes #9695) (#10699)
Browse files Browse the repository at this point in the history
  • Loading branch information
marla294 authored and platinumazure committed Aug 3, 2018
1 parent 6009239 commit dd6cb19
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docs/rules/no-return-await.md
@@ -1,6 +1,6 @@
# Disallows unnecessary `return await` (no-return-await)

Inside an `async function`, `return await` is useless. Since the return value of an `async function` is always wrapped in `Promise.resolve`, `return await` doesn't actually do anything except add extra time before the overarching Promise resolves or rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of `async function`s.
Inside an `async function`, `return await` is seldom useful. Since the return value of an `async function` is always wrapped in `Promise.resolve`, `return await` doesnt actually do anything except add extra time before the overarching Promise resolves or rejects. The only valid exception is if `return await` is used in a try/catch statement to catch errors from another Promise-based function.

## Rule Details

Expand All @@ -10,31 +10,31 @@ The following patterns are considered warnings:

```js
async function foo() {
return await bar();
return await bar();
}
```

The following patterns are not warnings:

```js
async function foo() {
return bar();
return bar();
}

async function foo() {
await bar();
return;
await bar();
return;
}

async function foo() {
const x = await bar();
return x;
const x = await bar();
return x;
}

async function foo() {
try {
return await bar();
} catch (error) {}
try {
return await bar();
} catch (error) {}
}
```

Expand Down

0 comments on commit dd6cb19

Please sign in to comment.