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

Appearance settings

Enhancement: [no-floating-promises] add an 'allowForKnownSafePromises' option #7008

Copy link
Copy link
Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg
Issue body actions

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-floating-promises

Description

For years, various community members have asked to add a type allowlist/blocklist or other "stop complaining about these specific areas" for no-floating-promises:

(including clearly duplicate issues to show how this is a relatively more requested option, and to surface the different use cases requested for)

Out of those, #5844's node:test is most convincing - as node:test is stable as of Node 20.0.0 (nodejs/node#46642 -> nodejs/node#46983), and returns Promise<void> for tests: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8730660c37a33dc0768b3f1e36b679294acc4988/types/node/test.d.ts#L134.

I propose we adopt the format discussed in #6017 & implemented in #4436 (see v6 docs) as a new allow option for no-floating-promises. We'd want to add some very explicitly, strongly worded descriptions in the docs as to why it's not an option we recommend using lightly.

Fail

async function test(name: string, executor: () => Promise<void>) {
  // ...
}

test("example", () => {});

Pass

import test from 'node:test';

test("example", () => {});

Additional Info

cc @armano2 @bradzacher as past people who, like me, have previously disagreed with the suggestion of adding this option.

Edit: to be clear, this is roughly what users would be able to specify in their ESLint config (pending naming bikeshedding):

"@typescript-eslint/no-floating-promises": ["error", {
  "allowForKnownSafePromises": [
    { "from": "package", "name": "SafePromise", "package": "some-fancy-package"
  ]
}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.