sindresorhus/eslint-plugin-unicorn
Use `Promise.withResolvers` instead of `new Promise()`?
Closed
#2,403 opened on Jul 22, 2024
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
I think in most cases need a promise, using Promise.withResolvers() should be more readable than new Promise(), because new Promise needs a new function scope.
I opened this issue instead of a rule proposal, since I'm not sure about it and want to discuss it first.
Welcome to post cases where new Promise() should be preferred.
The only case in my mind is the arrow function body.
const foo = () => new Promise(resolve => {
resolve()
});