Disallow returning value from Promise executor
See original GitHub issuePlease describe what the rule should do:
Disallows returning values of any kind from the Promise executor.
Value returned from Promise executor is ignored, but people may not be aware of it and they may think that returning e.g. another promise from the executor awaits that promise, or that the new promise (the outer one) is going to be rejected if the returned promise is rejected itself.
What category of rule is this? (place an “X” next to just one item)
[x] Warns about a potential error (problem)
Provide 2-3 code examples that this rule will warn about:
new Promise(() => {
return Promise.resolve(42);
});
new Promise(() => {
return false;
});
Why should this rule be included in ESLint (instead of a plugin)?
This rule would disallow returning anything from Promise executor function which is going to make original intent more clear, and prevent possible errors by expecting false behavior.
This rule is an extension of my previous (accepted) suggestion to help prevent issues when dealing with Promises.
Are you willing to submit a pull request to implement this rule?
Maybe.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12 (12 by maintainers)
Top GitHub Comments
Should the rule also disallow implicit return from arrow functions:
Valid code would be:
return cleanUpSomething()
could be also a false negative?I think that by default only
return;
should be allowed, but we can consider adding an option to allowreturn resolve()/return reject()
(or any call expression) later as an enhancement.