Skip to content

Commit 4f50f64

Browse files
docs: [return-await] make the rule no longer an extension of ESLint no-return-await (#10421)
* make return-await standalone * when not to use it * terser
1 parent 4e7f5f8 commit 4f50f64

File tree

8 files changed

+25
-11
lines changed

8 files changed

+25
-11
lines changed

packages/eslint-plugin/docs/rules/return-await.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ import TabItem from '@theme/TabItem';
99
>
1010
> See **https://typescript-eslint.io/rules/return-await** for documentation.
1111
12-
This rule builds on top of the [`eslint/no-return-await`](https://eslint.org/docs/rules/no-return-await) rule.
13-
It expands upon the base rule to add support for optionally requiring `return await` in certain cases.
14-
15-
The extended rule is named `return-await` instead of `no-return-await` because the extended rule can enforce the positive or the negative. Additionally, while the core rule is now deprecated, the extended rule is still useful in many contexts:
12+
In `async` functions, it is valid to return a promise-wrapped value or a value directly, both of which ultimately produce a promise with the same fulfillment value. Returning a value rather than a promise-wrapped value can have several subtle benefits:
1613

1714
- Returning an awaited promise [improves stack trace information](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#improving_stack_trace).
18-
- When the `return` statement is in `try...catch`, awaiting the promise also allows the promise's rejection to be caught instead of leaving the error to the caller.
15+
- When the `return` statement is in `try...catch`, awaiting the promise allows the promise's rejection to be caught instead of leaving the error to the caller.
1916
- Contrary to popular belief, `return await promise;` is [at least as fast as directly returning the promise](https://github.com/tc39/proposal-faster-promise-adoption).
2017

18+
This rule enforces consistent handling of whether to await promises before returning them.
19+
20+
:::info
21+
22+
This rule used to be considered an extension of the (now-deprecated) ESLint core rule [`no-return-await`](https://eslint.org/docs/latest/rules/no-return-await#options).
23+
Without type information, the only situations that could be flagged by `no-return-await` were of neutral-to-negative value, which eventually led to its deprecation.
24+
In contrast, with access to type information, `@typescript-eslint/return-await` delivers enough positive value to earn it a spot in our strict preset.
25+
26+
If you previously used `no-return-await`, this rule's `in-try-catch` option has the closest behavior to the `no-return-await` rule.
27+
28+
:::
29+
2130
## Options
2231

2332
```ts
@@ -326,3 +335,5 @@ async function validNever3() {
326335

327336
</TabItem>
328337
</Tabs>
338+
339+
{/* Intentionally Omitted: When Not To Use It */}

packages/eslint-plugin/src/configs/disable-type-checked.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';
99

1010
export = {
11-
parserOptions: { project: false, program: null, projectService: false },
11+
parserOptions: { program: null, project: false, projectService: false },
1212
rules: {
1313
'@typescript-eslint/await-thenable': 'off',
1414
'@typescript-eslint/consistent-return': 'off',

packages/eslint-plugin/src/configs/strict-type-checked-only.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export = {
6161
{
6262
allowAny: false,
6363
allowBoolean: false,
64+
allowNever: false,
6465
allowNullish: false,
6566
allowNumber: false,
6667
allowRegExp: false,
67-
allowNever: false,
6868
},
6969
],
7070
'no-return-await': 'off',

packages/eslint-plugin/src/rules/return-await.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default createRule({
3737
type: 'problem',
3838
docs: {
3939
description: 'Enforce consistent awaiting of returned promises',
40-
extendsBaseRule: 'no-return-await',
4140
recommended: {
4241
strict: ['error-handling-correctness-only'],
4342
},

packages/typescript-eslint/src/configs/disable-type-checked.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ export default (
7676
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off',
7777
},
7878
languageOptions: {
79-
parserOptions: { project: false, program: null, projectService: false },
79+
parserOptions: { program: null, project: false, projectService: false },
8080
},
8181
});

packages/typescript-eslint/src/configs/strict-type-checked-only.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export default (
7474
{
7575
allowAny: false,
7676
allowBoolean: false,
77+
allowNever: false,
7778
allowNullish: false,
7879
allowNumber: false,
7980
allowRegExp: false,
80-
allowNever: false,
8181
},
8282
],
8383
'no-return-await': 'off',

packages/typescript-eslint/src/configs/strict-type-checked.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export default (
107107
{
108108
allowAny: false,
109109
allowBoolean: false,
110+
allowNever: false,
110111
allowNullish: false,
111112
allowNumber: false,
112113
allowRegExp: false,
113-
allowNever: false,
114114
},
115115
],
116116
'no-return-await': 'off',

tools/scripts/generate-configs.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ async function main(): Promise<void> {
8989
),
9090
);
9191

92+
// special case - return-await used to be an extension, but no longer is.
93+
// See https://github.com/typescript-eslint/typescript-eslint/issues/9517
94+
BASE_RULES_TO_BE_OVERRIDDEN.set('return-await', 'no-return-await');
95+
9296
type RuleEntry = [string, ESLintPluginRuleModule];
9397

9498
const allRuleEntries: RuleEntry[] = Object.entries(eslintPlugin.rules).sort(

0 commit comments

Comments
 (0)