Rule proposal: check that function is not returning promise and non-promise #9296
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
enhancement: new plugin rule
New rule request for eslint-plugin
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
We have a number of public APIs in our project that return things like
string | Promise<string>
. In fact, we have so many of these that we have a helper type calledMaybePromise
. I believe it would be better if these functions always returned aPromise
. It would make a nicer API for callers because they would only have to worry about handling rejected promise errors and would not have to worry about errors that are thrown as wellI probably wouldn't want to apply this check to our whole project as internally we can have errors propagate in many functions, but I'd love to apply it to our public type definition file (
.d.ts
).Fail Cases
Pass Cases
Additional Info
promise-function-async
has a somewhat similar goal, but doesn't work for me because it ignores methods with explicit return types, which is one of the things I'd like to detect and disallow. It also has a ton of false positives on my existing codebase where it's almost always fine for me to just propagate errors upwardsThe text was updated successfully, but these errors were encountered: