Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
thisVioletHydra opened this issue Mar 25, 2023 · 1 comment
Closed
4 tasks done

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

thisVioletHydra opened this issue Mar 25, 2023 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@thisVioletHydra
Copy link

thisVioletHydra commented Mar 25, 2023

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

@thisVioletHydra thisVioletHydra added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 25, 2023
@bradzacher
Copy link
Member

This is working as expected.

When a promise is assigned to a variable - it is not floating because it is stored for later evaluation.

The assumption is that the variable will be either awaited, returned from a function, or passed to a function - I.e. Used in some way where it might later be awaited.

Duplicate of #5749, #3359

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2023
@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels Mar 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants