Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
To support this issue, I've createda sample repository to show the problem. The main issue is with types that support a "builder pattern". In other words, you can continually build onto a given object until you're ready to execute it with a.then
orawait
.
{"rules": {"@typescript-eslint/no-floating-promises":"error" }}
There are two issues displayed in this use-case.
Fastify. Fastify causes two classes of errors to be thrown in this example. The first is with
.register
. This one can pretty easily be ignored by adding avoid
in front of it. However, all of the Fastify examples don't show the need toawait
the returned promises. The second issue is with theirFastifyReply
object, which is likely more interesting to think about. It uses a builder pattern, allowing you to set properties before your fileres.send
. Each line adds a warning before the finalsend
, unless you addvoid
s.Knex QueryBuilder. The other issue displayed here is with the Knex QueryBuilder. Knex allows you to pass around a
QueryBuilder
object before finallyawait
-ing it to execute the query. Again, these errors can be supressed with avoid
until you're actually ready to execute the query.
importFastifyfrom'fastify';importFastifyCookiefrom'fastify-cookie';importknexfrom'knex';constdbClient=knex({});constapp=Fastify();// The docs for Fastify don't show a need to `await` these calls to `register`.// It would be nice to be able to safelist these usages somehow.app.register(FastifyCookie);app.get('/example',(_req,res)=>{// You're able to build up your response over multiple lines. These throw// linting errors since the FastifyReply type has a `then` method.res.header("x-some-header","foobar");res.send(200);})app.get('/dbquery',async(_req,res)=>{// This one is a bit tougher to think about solving for, since eventually// you'd want to validate that it's `await`-ed. However, it would still be// nice to provide some way to just ignore these types all together.constquery=dbClient('foos');query.orderBy('id','desc');constdbResult=awaitquery;res.send(JSON.stringify(dbResult));});app.listen(4000);
{"compilerOptions": {"target":"es2019","strict":true,"esModuleInterop":true,"skipLibCheck":true,"forceConsistentCasingInFileNames":true }}
Expected Result
It would be nice to be able to ignore certain types from producing errors. In this case, it'd be nice to be able to safelist theFastifyReply
type from producing warnings in this plugin.
Actual Result
10:1 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises 15:3 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises 16:3 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises 24:3 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises 26:3 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises 29:1 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises
Additional Info
I can work around this by placingvoid
in front of each of the calls I want to ignore. However, this is more of a feature request/brainstorming issue to think about ways we could reduce cluttering the code withvoid
statements in all of these cases.
Is this even something to consider fixing? Or maybe adding thevoid
in front of all calls to builder methods is explicit and desired?
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 4.4.0 |
@typescript-eslint/parser | 4.4.0 |
TypeScript | 4.0.3 |
ESLint | 7.10.0 |
node | 12.18.3 |