Comments (8)
Heh, I personally prefer this, but have memories of people getting β¨ very upset β¨ over it. Maybe we should put it in strict
to start?
from typescript-eslint.
What did people get upset about with return-await
? Returning an unawaited promise inside a try catch seems to invite for troubles. I also don't know why people ever want to return unawaited promises, except for very simple wrappersβfun fact, awaiting the promise does not make anything slower; it may actually make code faster than if you return the promise directly!
from typescript-eslint.
I don't have many primary resources that I can find in 5 minutes of searching π but vaguely:
- The venerable https://jakearchibald.com/2017/await-vs-return-vs-return-await explicitly says "Outside of try/catch blocks,
return await
is redundant - and that article still has good SEO - When https://eslint.org/docs/latest/rules/no-return-await was written, IIRC it was taken to heart by many
- Scattered old tweets from searching for
return await javascript
show folks occasionally suggesting a preference for less code (return a
overreturn await a
) and/or not wanting to pollute the call stack - Edit: this one is fun too, eslint/eslint#18166
it may actually make code faster than if you return the promise directly!
Do you have references?
Maybe relevant: eslint/eslint#18166
from typescript-eslint.
I'm big +1 to this, but, I am also concerned that the current rule is too opinionated, and would cause a lot of unnecessary flagging in existing codebases. I'd propose we have an unopinionated option that only flags on the parts of the rule that impact correctness, if we are to add the rule to recommended; see #9030. Note that all the disagreements center around the portion of the rule that I'm proposing to disable.
from typescript-eslint.
and would cause a lot of unnecessary flagging in existing codebases
The rule has an autofixer for any cases that aren't any
/unknown
- so why is extra initial flagging bad?
It brings the codebase into a consistent style immediately. Anecdotally I've found people generally don't write return await
so I don't think it would flag much.
from typescript-eslint.
people generally don't write
return await
...but they should! If you return myPromise
instead of return await myPromise
the call stack doesn't include the intermediary step.
I'm +1 to this provided the caveats Kirk mentioned are accounted for.
from typescript-eslint.
so why is extra initial flagging bad?
Mostly, it's just that I would be scared we'd not get the rule into a recommended preset at all if we reawaken the opinion-charged conversations referenced in #8667 (comment). The thought is that, strategically speaking, we could sidestep all that and still get the most important benefits (IMO) of return-await.
It brings the codebase into a consistent style immediately. Anecdotally I've found people generally don't write
return await
so I don't think it would flag much.
I completely agree that full consistency (whether in-try-catch
or, my preference, always
) should be the correct end goal for any codebases. Maybe this could be in a strict
or stylistic
config?
from typescript-eslint.
If backlash that it's too opinionated where it doesn't affect the outcome of execution is not a concern, then everything I've said is moot! π
from typescript-eslint.
Related Issues (20)
- Configs: Apply changes to config presets for v8 HOT 1
- Enhancement: [prefer-nullish-coalescing] should ignore Boolean constructor HOT 4
- Repo: Use ESLint v9 for our internal linting HOT 3
- feat(eslint-plugin): remove deprecated no-throw-literal rule HOT 1
- Docs: Updated typed linting docs for new project service
- Bug: incorrect peer dependencies in v8.0.0-alpha.10 packages HOT 6
- Parser: remove EXPERIMENTAL_useSourceOfProjectReferenceRedirect in favor of project service HOT 2
- Repo: publishing v8 canary versions failed - "Not Found - PUT https://registry.npmjs.org/@typescript-eslint/types - Not found" HOT 2
- Bug: Broken examples? HOT 1
- Docs: Quickstart guide should be clear on type: module not being a requirement HOT 7
- Repo: Failing to publish new alpha versions of v8 post-v8.0.0-alpha.10 HOT 2
- Bug: [v8.0.0-alpha.10] incorrect error message `Parsing error: "parserOptions.programs"` HOT 1
- Bug: [member-ordering] Not Detecting Order For Read-Only Fields Correctly HOT 1
- Bug: Default configuration following https://typescript-eslint.io/getting-started results in error HOT 1
- Bug(typescript-estree): always parse mts/mjs as ESM for non-type-aware parsing HOT 8
- Docs: Write blog post on the history of ban-types, {}, and object/Object HOT 1
- Bug: [no-unnecessary-boolean-literal-compare] False positive and unsafe fix with exactOptionalPropertyTypes HOT 6
- no-unsafe-call: ban calling Function HOT 14
- Types: `plugin` and `parser` types incompatible with ESLint types HOT 6
- Issue with the subDependencies of typescript-eslint HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-eslint.