Skip to content

Bug: [no-floating-promises] <Promises must be awaited> #6766

Closed as not planned
@thisVioletHydra

Description

@thisVioletHydra

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.0.2&sourceType=module&code=AQWAUMwJYHYC4FMBOAzAhgYwcA6rAJgPYDuwA3uJJMQJ5IC2AFoQDYIBc5lVkGSCaRJwA8AFQB8ACgQAPRDADOUQjACS+APydRAGmD0o9BKJoAHBFuC7gzBXBhojl0QEpgAXnHAACkkIGFBGEAVxgAaxgSGHEAbm5IAF84iGAE8AwVO2AUQkIPKkk3Ty4wbgzFOGBZeSUVdXyAcgbk3kzKgyMTc0bmsrabQjsHIx7kvorgAHMWQgAjNBYcOiZWbHdgYgISADpaBmY2FuByrLJj-kFsBPzpuYWl-dWx0pSTyv4FYJZK9b4BRGkcgQimUanweg6xjMCD0tnsjgQLhiwAA9CjgAA5ADy3gAoqBXhcAdVgbUwRDDFDzLDBvCjEjIGjgHBGFAFMAAOJYrEAEQJVG4-DgwSQMGAHy+cGSaQg4AAboQoPhsrlCsjgEA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYkACAXAngA4oDG0AlobgLQrzkB2uA9AwPbUBm8bAhrowDm1QtDYBbcshTooiaGOiQAviGVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

normal lint code


 create(extensionId, mimeType, hostname);

LINTER:
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.eslint@typescript-eslint/no-floating-promises
invalid lint code
 
const result =   create(extensionId, mimeType, hostname);

LINTER:
const create: <string>(extensionId?: string | undefined, mimeType?: string | undefined, hostname?: string | undefined) => Promise<WyrmInstance>
 

ESLint Config

require('@rushstack/eslint-patch/modern-module-resolution');

const rules = require('./.eslint-rules.cjs');
const _tsconfig = require('./tsconfig.json');
const _alias = _tsconfig.compilerOptions.paths;

const arrayType = ['.js', '.mjs', '.jsx', '.ts', '.d.ts', '.tsx'];
const pluginsRule = ['unicorn', 'import', 'json', 'promise', 'optimize-regex', 'sonarjs'];

const listFiles = {
  extVue: ['*.vue', '*.html'],
  extJs: ['*.js', '*.cjs', '*.mjs', '*.jsx', '*.ts', '*.d.ts', '*.tsx'],
};

const extendsRule = [
  './.eslintrc-auto-import.json',
  'eslint:recommended',

  'plugin:import/recommended',
  'plugin:import/typescript',

  'plugin:sonarjs/recommended',
  'plugin:json/recommended',
  'plugin:unicorn/all',
];

const envRule = {
  browser: true,
  es6: true,
  node: true,
  jest: true,
};

const settingsRule = {
  'import/parsers': { '@typescript-eslint/parser': ['.ts', '.tsx'] },

  'import/extensions': arrayType,
  'import/resolver': {
    typescript: {
      alwaysTryTypes: true,
      project: './tsconfig.json',
    },
    alias: true,

    node: { extensions: arrayType },

    'eslint-import-resolver-custom-alias': {
      alias: _alias,
      extensions: arrayType,
    },
  },
  'prettier-vue': {
    SFCBlocks: {
      template: true,
      script: true,
      style: true,

      customBlocks: {
        docs: { lang: 'markdown' },
        config: { lang: 'json' },
        module: { lang: 'js' },
        comments: false,
      },
    },
    usePrettierrc: true,

    fileInfoOptions: {
      withNodeModules: false,
    },
  },
};

// ---------------- START ----------------
module.exports = {
  root: true,
  ignorePatterns: ['!.*', 'dist', 'node_modules'],

  overrides: [
    {
      rules,
      files: listFiles.extJs,
      env: envRule,
      parser: '@typescript-eslint/parser',
      parserOptions: {
        extraFileExtensions: ['.vue'],
        sourceType: 'module',
        ecmaVersion: 'latest',
        ecmaFeatures: { jsx: true },
        project: 'tsconfig.json',
        tsconfigRootDir: process.cwd(),
      },
      extends: [
        ...extendsRule,
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
      ],
      plugins: pluginsRule,
      settings: settingsRule,
    },

    {
      rules,
      env: {
        ...envRule,
        'vue/setup-compiler-macros': true,
      },
      files: listFiles.extVue,
      parser: 'vue-eslint-parser',
      parserOptions: {
        extraFileExtensions: ['.vue'],
        sourceType: 'module',
        ecmaVersion: 'latest',
        parser: '@typescript-eslint/parser',
        ecmaFeatures: { jsx: true },
        project: 'tsconfig.json',
        '<i18n>': '@typescript-eslint/parser',
      },
      extends: [
        ...extendsRule,
        'plugin:vue/vue3-recommended',
        'plugin:vue/vue3-essential',
        '@vue/eslint-config-typescript/recommended',
        '@vue/eslint-config-prettier',
      ],
      plugins: [...pluginsRule, 'vue'],
      settings: settingsRule,
    },
  ],
};

tsconfig

{
  "display": "TypeScript compiler",
  "compilerOptions": {
    "rootDir": ".",
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "composite": true,
    "declaration": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "module": "ESNext",
    "moduleResolution": "Node",
    "noEmit": true,
    "noImplicitAny": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "pretty": true,
    "resolveJsonModule": true,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": true,
    "target": "ESNext",
    "useDefineForClassFields": true,

    "lib": ["DOM", "DOM.Iterable", "ESNext", "ESNext.AsyncIterable"],
    "paths": {
      "~~assets/*": ["src/assets/*"],
      "~~components/*": ["src/components/*"],
      "~~hooks/*": ["src/hooks/*"],
      "~~interfaces/*": ["src/interfaces/*"],
      "~~libs/*": ["src/libs/*"],
      "~~pages/*": ["src/pages/*"],
      "~~routers/*": ["src/routers/*"],
      "~~stores/*": ["src/stores/*"],
      "~~/*": ["src/*"],
      "~~fonts/*": ["src/assets/fonts/*"],
      "~~styles/*": ["src/assets/styles/*"],
      "~~ScreenHello/*": ["src/components/ScreenHello/*"],
      "~~vString/*": ["src/hooks/vString/*"],
      "~~Page/*": ["src/pages/Page/*"],
      "~~instance/*": ["src/routers/instance/*"],
      "~~listRoutes/*": ["src/routers/listRoutes/*"],
      "~~ScreenStart/*": ["src/components/ScreenStart/*"],
      "~~Screen/*": ["src/components/Screen/*"],
      "~~Hello/*": ["src/components/Screen/Hello/*"],
      "~~Start/*": ["src/components/Screen/Start/*"]
    },
    "typeRoots": ["./node_modules/@types", ".", "index.d.ts", "types.d.ts", "oauthjs/types.d.ts"],
    "types": ["@types/node", "vite/client"]
  },
  "filesGlob": ["**/*.ts"],
  "files": ["auto-imports.d.ts", "components.d.ts"],
  "include": ["**/*.ts", "**/*.d.ts", "**/*.json", "**/*.md", "**/*.vue"],
  "exclude": ["node_modules", "node_modules/", "dist", "public", ".viteCache", "./legacy", "main.ts"]
}

Expected Result

when assigned to a variable, the expected promise is not found by eslint
without a variable, everything works and the function is recognized as a promise

Actual Result

a function definition is expected that this is a promise

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existspackage: 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