vuejs / eslint-config-typescript

eslint-config-typescript for vue projects
MIT License
115 stars 27 forks source link

typescript-eslint/no-floating-promises - You have used a rule which requires parserServices to be generated #52

Open rezelute opened 1 year ago

rezelute commented 1 year ago

The readme says that we can use any rule in @typescript-eslint/eslint-plugin however when I try using no-floating-promises, I keep getting the following error:

Error: Error while loading rule '@typescript-eslint/no-floating-promises': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.

This is what I have in my eslint config file:

extends: ["plugin:vue/vue3-recommended", "eslint:recommended", "@vue/eslint-config-typescript/recommended", "@vue/eslint-config-prettier"],
   parserOptions: {
      ecmaVersion: 2022, // needed to support class static properties
   },

I am using vue3/vite with Typescript. Any other rule that I have used in the past for example: @typescript-eslint/no-unused-vars or @typescript-eslint/no-explicit-any seems to work fine. Is there something special about typescript-eslint/no-floating-promises ?

Thanks!

decryphe commented 1 year ago

I can confirm, there is a regression between versions 10.0.0 and 11.0.0 that breaks linting many TypeScript lints in *.vue files. I'm using a vue3/vue-cli with TypeScript.

To answer the question: Yes, @typescript-eslint/no-floating-promises needs knowledge of types, which needs the TypeScript compiler/parser. Many other lints from @typescript-eslint do not need that and make do with a JS parser.

How to reproduce (almost minimal example):

  1. Create a new project using vue-cli with the following .vuerc preset.
  2. Adjust package.json and .eslintrc.js to the following content.
  3. Add an .eslintignore with the following content.
  4. Switch between @vue/eslint-config-typescript versions 10.0.0 and 11.0.0 to observe the regression.

Content of .vuerc:

{
  "useTaobaoRegistry": false,
  "presets": {
    "with-regression": {
      "useConfigFiles": true,
      "plugins": {
        "@vue/cli-plugin-typescript": {
          "classComponent": false
        },
        "@vue/cli-plugin-router": {
          "historyMode": false
        },
        "@vue/cli-plugin-eslint": {
          "config": "prettier",
          "lintOn": [
            "save"
          ]
        },
        "@vue/cli-plugin-unit-jest": {}
      },
      "vueVersion": "3",
      "cssPreprocessor": "dart-sass"
    }
  }
}

Content of package.json:

{
  "name": "testproj",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "vue": "^3.2.13",
    "vue-router": "^4.0.3"
  },
  "devDependencies": {
    "@types/jest": "*",
    "@typescript-eslint/eslint-plugin": "*",
    "@typescript-eslint/parser": "*",
    "@vue/cli-plugin-eslint": "*",
    "@vue/cli-plugin-router": "*",
    "@vue/cli-plugin-typescript": "*",
    "@vue/cli-plugin-unit-jest": "*",
    "@vue/cli-service": "*",
    "@vue/eslint-config-prettier": "*",
    "@vue/eslint-config-typescript": "11.0.0",
    "@vue/test-utils": "*",
    "@vue/vue3-jest": "*",
    "babel-jest": "*",
    "eslint": "*",
    "eslint-config-prettier": "*",
    "eslint-plugin-prettier": "*",
    "eslint-plugin-sort-class-members": "*",
    "eslint-plugin-vue": "*",
    "eslint-plugin-vuejs-accessibility": "*",
    "jest": "*",
    "prettier": "*",
    "sass": "*",
    "sass-loader": "*",
    "ts-jest": "*",
    "typescript": "*"
  }
}

Content of .eslintrc.js:

module.exports = {
  env: {
    node: true,
  },
  extends: [
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/strict",
    "plugin:vue/vue3-essential",
    "plugin:vue/vue3-recommended",
    "plugin:vuejs-accessibility/recommended",
    "plugin:prettier/recommended",
    "eslint:recommended",
    "@vue/prettier",
    "@vue/typescript/recommended",
    "@vue/eslint-config-typescript/recommended",
  ],
  overrides: [
    {
      env: {
        jest: true,
      },
      files: [
        "**/__tests__/*.{j,t}s?(x)",
        "**/tests/unit/**/*.spec.{j,t}s?(x)",
      ],
    },
  ],
  parserOptions: {
    ecmaVersion: 2020,
    project: ["./tsconfig.json"],
  },
  plugins: ["sort-class-members", "@typescript-eslint"],
  root: true,
  rules: {
    "@typescript-eslint/strict-boolean-expressions": "warn",
  },
};

Content of .eslintignore:

.eslintrc.js
*.js
sceee commented 1 year ago

Did anyone find a workaround to get @typescript-eslint/no-floating-promises working with @vue/eslint-config-typescript? I tried setting parserOptions.project but I can't seem to get it working.

patrickelectric commented 6 months ago

any update on that ?

xmd5a commented 1 month ago

For those who have the same problem.

I managed to solve this issue with the solution presented in this comment: https://github.com/microsoft/vscode-eslint/issues/1537#issuecomment-1281209527