From 853d32baa8934c08b59a738470b72522e1505f6f Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Wed, 26 Jul 2023 11:48:22 -0400 Subject: [PATCH] feat: deprecate no-return-await (#17417) * 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 * Update lib/rules/no-return-await.js Co-authored-by: Milos Djermanovic * Update docs/src/rules/no-return-await.md --------- Co-authored-by: Milos Djermanovic Co-authored-by: Nicholas C. Zakas --- docs/src/_data/further_reading_links.json | 7 +++++++ docs/src/_data/rules.json | 11 ++++------- docs/src/_data/rules_meta.json | 2 ++ docs/src/rules/no-return-await.md | 2 ++ lib/rules/no-return-await.js | 5 +++++ packages/js/src/configs/eslint-all.js | 1 - 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/src/_data/further_reading_links.json b/docs/src/_data/further_reading_links.json index 120dd37032f..e66ef76ce69 100644 --- a/docs/src/_data/further_reading_links.json +++ b/docs/src/_data/further_reading_links.json @@ -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." } } \ No newline at end of file diff --git a/docs/src/_data/rules.json b/docs/src/_data/rules.json index 45caaa9f031..15fc4227d5f 100644 --- a/docs/src/_data/rules.json +++ b/docs/src/_data/rules.json @@ -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", @@ -1983,6 +1976,10 @@ "name": "no-restricted-modules", "replacedBy": [] }, + { + "name": "no-return-await", + "replacedBy": [] + }, { "name": "no-spaced-func", "replacedBy": [ diff --git a/docs/src/_data/rules_meta.json b/docs/src/_data/rules_meta.json index 6d9fb3d5a22..450c073c54d 100644 --- a/docs/src/_data/rules_meta.json +++ b/docs/src/_data/rules_meta.json @@ -1578,6 +1578,8 @@ "recommended": false, "url": "https://eslint.org/docs/latest/rules/no-return-await" }, + "deprecated": true, + "replacedBy": [], "fixable": null }, "no-script-url": { diff --git a/docs/src/rules/no-return-await.md b/docs/src/rules/no-return-await.md index 8f42100cfff..80328c09d8d 100644 --- a/docs/src/rules/no-return-await.md +++ b/docs/src/rules/no-return-await.md @@ -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. diff --git a/lib/rules/no-return-await.js b/lib/rules/no-return-await.js index b5abf14c69b..77abda0cadf 100644 --- a/lib/rules/no-return-await.js +++ b/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"; @@ -26,6 +27,10 @@ module.exports = { fixable: null, + deprecated: true, + + replacedBy: [], + schema: [ ], diff --git a/packages/js/src/configs/eslint-all.js b/packages/js/src/configs/eslint-all.js index f3a415cce5c..177ff92f316 100644 --- a/packages/js/src/configs/eslint-all.js +++ b/packages/js/src/configs/eslint-all.js @@ -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",