Skip to content

Commit

Permalink
feat: deprecate no-return-await (#17417)
Browse files Browse the repository at this point in the history
* fix: deprecate no-return-await

The original intent of this rule no longer applies due to the fact Javascript now handles native `Promises` differently. It can no be slower to remove `await` rather than keeping it.

Fixes #17345

* Update docs/src/rules/no-return-await.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update lib/rules/no-return-await.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update docs/src/rules/no-return-await.md

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
  • Loading branch information
3 people committed Jul 26, 2023
1 parent d4f02e4 commit 853d32b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
7 changes: 7 additions & 0 deletions docs/src/_data/further_reading_links.json
Expand Up @@ -719,5 +719,12 @@
"logo": "https://tc39.es/ecma262/img/favicon.ico",
"title": "ECMAScript® 2023 Language Specification",
"description": null
},
"https://v8.dev/blog/fast-async": {
"domain": "v8.dev",
"url": "https://v8.dev/blog/fast-async",
"logo": "https://v8.dev/favicon.ico",
"title": "Faster async functions and promises · V8",
"description": "Faster and easier-to-debug async functions and promises are coming to V8 v7.2 / Chrome 72."
}
}
11 changes: 4 additions & 7 deletions docs/src/_data/rules.json
Expand Up @@ -1062,13 +1062,6 @@
"fixable": false,
"hasSuggestions": false
},
{
"name": "no-return-await",
"description": "Disallow unnecessary `return await`",
"recommended": false,
"fixable": false,
"hasSuggestions": true
},
{
"name": "no-script-url",
"description": "Disallow `javascript:` urls",
Expand Down Expand Up @@ -1983,6 +1976,10 @@
"name": "no-restricted-modules",
"replacedBy": []
},
{
"name": "no-return-await",
"replacedBy": []
},
{
"name": "no-spaced-func",
"replacedBy": [
Expand Down
2 changes: 2 additions & 0 deletions docs/src/_data/rules_meta.json
Expand Up @@ -1578,6 +1578,8 @@
"recommended": false,
"url": "https://eslint.org/docs/latest/rules/no-return-await"
},
"deprecated": true,
"replacedBy": [],
"fixable": null
},
"no-script-url": {
Expand Down
2 changes: 2 additions & 0 deletions docs/src/rules/no-return-await.md
Expand Up @@ -2,10 +2,12 @@
title: no-return-await
rule_type: suggestion
further_reading:
- https://v8.dev/blog/fast-async
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
- https://jakearchibald.com/2017/await-vs-return-vs-return-await/
---

This rule was **deprecated** in ESLint v8.46.0 with no replacement. The original intent of this rule no longer applies due to the fact JavaScript now handles native `Promises` differently. It can now be slower to remove `await` rather than keeping it. More technical information can be found in [this V8 blog entry](https://v8.dev/blog/fast-async).

Using `return await` inside an `async function` keeps the current function in the call stack until the Promise that is being awaited has resolved, at the cost of an extra microtask before resolving the outer Promise. `return await` can also be used in a try/catch statement to catch errors from another function that returns a Promise.

Expand Down
5 changes: 5 additions & 0 deletions lib/rules/no-return-await.js
@@ -1,6 +1,7 @@
/**
* @fileoverview Disallows unnecessary `return await`
* @author Jordan Harband
* @deprecated in ESLint v8.46.0
*/
"use strict";

Expand All @@ -26,6 +27,10 @@ module.exports = {

fixable: null,

deprecated: true,

replacedBy: [],

schema: [
],

Expand Down
1 change: 0 additions & 1 deletion packages/js/src/configs/eslint-all.js
Expand Up @@ -172,7 +172,6 @@ module.exports = Object.freeze({
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-assign": "error",
"no-self-compare": "error",
Expand Down

0 comments on commit 853d32b

Please sign in to comment.