如何修复 eslintrc 文件与您的项目配置不匹配?
Posted
技术标签:
【中文标题】如何修复 eslintrc 文件与您的项目配置不匹配?【英文标题】:How to fix eslintrc The file does not match your project config? 【发布时间】:2020-11-16 23:11:13 【问题描述】:在我的打字稿项目中,我使用的是 eslint。下面的文件在根目录下,我还有子文件夹/dist
和/src
。
eslintrc.js
module.exports =
root: true,
parser: '@typescript-eslint/parser',
parserOptions:
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
,
rules:
strict: 'error',
semi: ['error', 'always'],
'no-cond-assign': ['error', 'always'],
,
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
tsconfig.json
"compilerOptions":
"outDir": "dist",
"noImplicitAny": true,
"moduleResolution": "Node",
"resolveJsonModule": true,
"module": "ES2020",
"target": "ES2020",
"lib": ["ES2020"],
"allowJs": false,
"alwaysStrict": true
,
"include": ["src"]
上面的module
这个词有一条红线表示这个错误
Parsing error: "parserOptions.project" has been set for @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. eslint
我该如何解决这个问题?
【问题讨论】:
您的问题已在此处得到解答***.com/questions/61956555/…> 【参考方案1】:更新您的 eslintrc.js
以包括:
ignorePatterns: ['.eslintrc.js']
【讨论】:
在阅读链接线程中的答案后,这似乎是最正确和“独立”的答案。 最好将其添加到您的 tsconfig.json 中:***.com/a/64283139/1345639 这也是使用级联eslintrc文件的解决方案【参考方案2】:这个错误是关于什么的?
烦人的错误基本上是说文件eslintrc.js
本身是两者:
-
由 ESLint 发现,但是
与应该 lint 的文件列表不匹配
所以,ESLint 不知道该怎么做,吓坏了!
请注意,虽然此文件不包含您的代码,但您应该决定是否要对该文件进行 linted(例如,制表符与空格,或双引号与单引号)。
应该怎么做?
您可以从上面的冲突情况中省略 (1) 或 (2)。
解决方案 1:告诉 ESLint 忽略文件
这更容易。只需将文件名(例如.eslintrc.js
)添加到.eslintignore
。
您还可以查看case 1.3 of my answer, here 了解不同的操作方式。
优点:快速。简单。无痛。 缺点:此文件的格式可能在制表符/空格或引号样式方面与其他文件不一致。解决方案 2:告诉 ESLint 对这个文件进行 lint(首选)
Typescript-ESLint 通过parserOptions > project
从tsconfig.json
获取要包含的文件列表。
因此,您可以将文件添加到现有 tsconfig.json
(解决方案 2.1)或创建辅助 tsconfig.eslint.json
以包含此类文件,您希望由 typescript-eslint 进行 linted,但不一定由Typescript 编译器。
解决方案 2.1:将其添加到现有的 tsconfig.json
// in tsconfig.json ...
"include": [
".eslintrc.js",
// ...
]
解决方案 2.2:将其添加到单独的 tsconfig.eslint.json
文件中
使用此内容创建文件名tsconfig.eslint.json
:
// new file: tsconfig.eslint.json
"include": [
".eslintrc.js"
]
然后将其注入eslintrc.js
的parserOptions
> project
(是的,project
接受字符串和字符串数组):
// in eslintrc.js ...
parserOptions:
project: [
resolve(__dirname, './tsconfig.json'),
resolve(__dirname, './tsconfig.eslint.json'),
],
附言。 This answer 非常相似,我将对此表示赞赏。
【讨论】:
谢谢,将.eslintrc.js
添加到项目中明确地为我解决了这个问题。我认为我的 glob 模式应该已经覆盖了它,但显然他们没有。
精彩的解释让事情变得清晰,非常感谢!【参考方案3】:
同样的错误,这对我有用: https://github.com/nestjs/nest/issues/4900#issuecomment-669743374 https://github.com/nestjs/nest/issues/4900#issuecomment-707330674
看起来配置文件必须命名为 .eslintrc 并使用 json 格式而不是 .eslintrc.js 并且 parserOptions.createDefaultProgram 必须设置为 true
【讨论】:
可能是createDefaultProgram
'修复'了它,但这会占用更多内存:github.com/typescript-eslint/typescript-eslint/issues/…以上是关于如何修复 eslintrc 文件与您的项目配置不匹配?的主要内容,如果未能解决你的问题,请参考以下文章
检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 1 行的 '' 附近使用如何修复 [关闭]
权利文件与您的配置文件中指定的不匹配。(0xE8008016)