Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Updated no return await documentation (fixes #9695) #10699

Merged
merged 2 commits into from
Aug 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/rules/no-return-await.md
Original file line number Diff line number Diff line change
@@ -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