提问者:小点点

为什么@typescript-eslint/parser包含在我的tsconfig.json中配置的文件之外的文件?


我得到了错误:-

Parsing error: "parserOptions.project" has been set for u/typescript-eslint/parser.

The file does not match your project config: .eslintrc.js.

The file must be included in at least one of the projects provided.

IDE-WebStorm 20.1.1

项目结构:-

node_modules

src

--- testfile.js

.eslintrc.js

.prettierrc.js

baseeslint.js

package.json

tsconfig.json

.eslintrc。js:-

module.exports = {
extends: ['./baseeslint'],
parserOptions: {
project: './tsconfig.json'
},
rules: {}
}

baseeslint。js:-

module.exports = {

parser: '@typescript-eslint/parser'

}

tsconfig.json:-

{

"include": [

"/src/**/*.ts",

"/src/**/*.tsx"

],

"exclude": ["node_modules"],

"compilerOptions": {

"outDir": "./lib",

"types": ["styled-components", "react", "@types/react-router-dom", "reactstrap"]

}

}

我完全不知道为什么会这样?我假设它会忽略根目录中的文件,尤其是我的tsconfg.json中指定的include?

任何帮助都将不胜感激。

编辑:-

我的解决办法,是不是应该帮助别人...

我将ignorePatterns配置添加到我的.eslintrc中。js文件:-

module.exports = {
  extends: ["mycustom/eslint-config"],
  parserOptions: {
    project: './tsconfig.json'
  },
  ignorePatterns: ["/*.*"],
  rules: {}
}

这也可以通过.eslintinignore来实现(参见下面安东·贝索诺夫的回答)。

与此相关的另一件可能对其他人有用的事情是我使用的VScode配置(在发布原始问题后,我从WebStorm切换到VScode)。我非常喜欢在save上运行eslint fix,但我不希望它试图对所有文件都这样做。我的项目文件(只有我的项目文件)都是.ts/.tsx。设置中的以下选项。json允许保存时修复,不包括我的repo中的每个文件:-

{
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "eslint.probe": [
        "typescript",
        "typescriptreact"
    ],
}

如果是eslint。未指定探针,默认为:-

[“javascript”,“javascriptreact”,“typescript”,“typescriptreact”,“html”,“vue”]

有关VSCode ESLint扩展设置的更多信息,请参见此处。


共3个答案

匿名用户

为什么会这样?

我不完全确定,但似乎@typecript-eslint/parser尝试将eslint配置中包含的文件(例如通过扩展名)与tsconfig.json中包含的文件进行比较。由于. js文件由@typecript-eslint/parser覆盖,并且根据您的eslint配置,该文件可能包含在eslint运行中。但是因为该文件未包含在tsconfig中,您会收到此错误。

如何修复?

根据您的情况,您可以选择其中之一:

  1. 您可以在中忽略它。eslintinignore。这就是@U4EA所做的
    "include": [
        ".eslintrc.js",
        // another includes
    ]
{
    "include": [
        ".eslintrc.js"
    ]
}

并仅将此文件用于eslint:

    parserOptions: {
        project: [
            './tsconfig.eslint.json',
            './packages/*/tsconfig.json',
        ],
    },

匿名用户

您也可以忽略。eslintrc。js in.eslintrc。js本身,为您保存一个附加文件:

"ignorePatterns": [
    ".eslintrc.js"
],

匿名用户

可以帮助VS代码用户,卸载或禁用ESLint扩展可能会解决这个问题,它对我很有用:)