Skip to content

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

Open
@cbrgpl

Description

@cbrgpl

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?

  • vue-eslint-parser@9.4.2
  • eslint-plugin-vue@9.24.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions