Skip to content
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

Cannot use ts-rules which requires "project" property when you enable both js and ts languages linting #229

Open
4 tasks done
cbrgpl opened this issue Apr 3, 2024 · 3 comments

Comments

@cbrgpl
Copy link

cbrgpl commented Apr 3, 2024

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

  • I'm using eslint-plugin-vue.
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-vue repo and open the issue in eslint-plugin-vue repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.57.0

What version of eslint-plugin-vue and vue-eslint-parser are you using?

What did you do?

Configuration
{
  // ...
  files: [ '*.vue' ],
    parser: 'vue-eslint-parser',
    parserOptions: {
      parser: {
        'js': '@babel/eslint-parser',
        'ts': '@typescript-eslint/parser',
      },
      project: [ './tsconfig.json' ],
    },
  // ...
}

What did you expect to happen?

I expect @typescript-eslint/consistent-type-imports rule will work correctly. It requires providing project option for @typescript-eslint/parser. If I don't lint *.vue files it works correctly.

What actually happened?

I get error. I tried to fix it and understood that happens because of both languages linting enabled. When I change config to this:

{
  // ...
  files: [ '*.vue' ],
    parser: 'vue-eslint-parser',
    parserOptions: {
      parser: '@typescript-eslint/parser',
      project: [ './tsconfig.json' ],
    },
  // ...
}

Eslint works correctly(but ignores js written components by obviously reasons). I suppose @typescript-eslint/parser does not get value of project from parserOptions, when you configured config by the first way

Error: Error while loading rule '@typescript-eslint/consistent-type-imports': 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.
Parser: /home/dmitry/Templates/crm-frontend-v2/node_modules/vue-eslint-parser/index.js
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
Occurred while linting /home/dmitry/Templates/crm-frontend-v2/src/App.vue
    at throwError (/home/dmitry/Templates/crm-frontend-v2/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:40:11)
    at getParserServices (/home/dmitry/Templates/crm-frontend-v2/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:20:9)
    at create (/home/dmitry/Templates/crm-frontend-v2/node_modules/@typescript-eslint/eslint-plugin/dist/rules/consistent-type-imports.js:85:68)
    at Object.create (/home/dmitry/Templates/crm-frontend-v2/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20)
    at createRuleListeners (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:895:21)
    at /home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1066:110
    at Array.forEach (<anonymous>)
    at runRules (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1003:34)
    at Linter._verifyWithoutProcessors (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1355:31)
    at /home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1913:29
    at Array.map (<anonymous>)
    at Linter._verifyWithProcessor (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1908:37)
    at Linter._verifyWithConfigArray (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1800:25)
    at Linter.verify (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:1437:65)
    at Linter.verifyAndFix (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/linter/linter.js:2068:29)
    at verifyText (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/cli-engine/cli-engine.js:254:48)
    at CLIEngine.executeOnFiles (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/cli-engine/cli-engine.js:834:28)
    at ESLint.lintFiles (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/eslint/eslint.js:551:23)
    at Object.execute (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/lib/cli.js:421:36)
    at async main (/home/dmitry/Templates/crm-frontend-v2/node_modules/eslint/bin/eslint.js:152:22)

Link to Minimal Reproducible Example

I have debuged it already

Additional comments

No response

@cbrgpl
Copy link
Author

cbrgpl commented Apr 3, 2024

I decided to turn off the rule, but I would like to have this possibility, because some component could be written in js due to some circumstances and I cannot disable js linting, but I want to use some useful rules for ts

@cbrgpl cbrgpl changed the title Cannot use ts-rules which requires "project" property when you both js and js languages lingting Cannot use ts-rules which requires "project" property when you enable both js and js languages linting Apr 3, 2024
@cbrgpl cbrgpl changed the title Cannot use ts-rules which requires "project" property when you enable both js and js languages linting Cannot use ts-rules which requires "project" property when you enable both js and ts languages linting Apr 3, 2024
@jpoep
Copy link

jpoep commented Apr 11, 2024

I'm having the same issue. Using @typescript-eslint/eslint-plugin and @typescript-eslint/parser @ versions ^6.21 works, but is only compatible with typescript up to ^5.3.

It's not optimal but at least fixes the issue you mentioned for now.

@MrFox131
Copy link

Any news from contributors bout it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants