-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Repro
{
"rules": {
"@typescript-eslint/promise-function-async": [
"error",
{ "allowedPromiseNames": [ "QueryBuilder" ] }
]
}
}import { Foo } from './models/foo';
import { QueryBuilder } from 'objection';
function foo(): QueryBuilder<Foo> {
return Foo.query();
}Expected Result
No errors.
Actual Result
error Functions that return promises must be async @typescript-eslint/promise-function-async
Additional Info
I'm looking to confugre the promise-function-async rule such that it allows non-async functions returning certain types, even if they are promises or promise-like. My use case is the Objection.js QueryBuilder which is a promise-like that executes the query you're building as soon as its then method is called. I need a function that returns it without executing it in order to do further manipulation, and adding async to this function will make the intended use of this function confusing.
Based on the name, it seems like the "allowPromiseNames" option should do this, but according to both the docs and implemented behavior shown above, it actually does the opposite. Instead of allowing the provided list of promise names, it considers the provided names promises even if they weren't before.
Note that in my case, this error is reported with or without the "allowedPromiseNames" option present, since QueryBuilder is a promise-like.
I'd like to add a true "allowPromiseNames" option, and rename the existing one to something else. Possibly "additionalPromiseNames." I could add the configuration under a different name, but I feel the presence existing one would be confusing.
Of course, this would be a breaking change, so I'd like to ensure this seems reasonable to you all before making a PR.
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin |
2.19.0 |
@typescript-eslint/parser |
2.19.0 |
TypeScript |
3.5.3 |
ESLint |
6.8.0 |
node |
10.16.0 |
npm |
6.13.7 |