Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-floating-promises] Ability to ignore certain types from producing errors #2640

Closed
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on
@blimmer

Description

@blimmer
  • 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.

  1. 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 addvoids.

  2. Knex QueryBuilder. The other issue displayed here is with the Knex QueryBuilder. Knex allows you to pass around aQueryBuilder 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

packageversion
@typescript-eslint/eslint-plugin4.4.0
@typescript-eslint/parser4.4.0
TypeScript4.0.3
ESLint7.10.0
node12.18.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp