Skip to content

Bug: [no-floating-promises] allowForKnownSafeCalls doesn't work with string TypeOrValueSpecifiers #11423

@JHawk0224

Description

@JHawk0224

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.8.2&fileType=.tsx&code=MYewdgzgLgBATgQzAExAWwIIQJ5mAMQFc8oBLcGAXhgRzxgAoBKKgPhgG8AoGeAUyiE4YGAAU46UhD4A6OHwggANgDc%2BDKHEJ8mXAL5cuiFOiy4CxYGXDMuQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oDN4OBDfMwDmtYtA4BbSshTowAbXDYciaBOiQANMpVYV2SP3h8A7gDEO0ANKdTTAMr9uiAMLH4qDEoMGY-JgATKQBBZEImMnNYSKEOJkhdAwBdJIgAXyTUjJB0oA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const randomAsyncFunction = async () => {
  return Promise.resolve(true)
}

randomAsyncFunction()

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-floating-promises": [
      "error",
      {
        "allowForKnownSafeCalls": [
          "randomAsyncFunction"
        ]
      }
    ]
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

According to the docs, there should be no lint issue with calling this function since it's listed in the allow list.

Actual Result

The lint rules still say it must be dealt with.

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the void operator. 5:1 - 5:22

Add void operator to ignore.
Add await operator.

Additional Info

I believe this has to do with isKnownSafePromiseReturn, it never calls valueMatchesSomeSpecifier. The incorrect behavior also happens when trying to reference a function from a local file with "from": "file".

Something like this?

function isKnownSafePromiseReturn(node) {
    if (node.type !== utils_1.AST_NODE_TYPES.CallExpression) {
        return false;
    }
    const type = services.getTypeAtLocation(node.callee);
    if ((0, util_1.valueMatchesSomeSpecifier)(node.callee, allowForKnownSafeCalls, services.program, type)) {
        return true;
    }
    return (0, util_1.typeMatchesSomeSpecifier)(type, allowForKnownSafeCalls, services.program);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy