【发布时间】:2020-07-04 10:20:36
【问题描述】:
最近在我们的项目中我们迁移到使用@typescript-eslint/parser 来慢慢从 tslint 迁移。一切都很顺利,但我有一个小问题/问题我无法解决。
我是否需要在 tsconfig 排除数组以及 .eslintrc 导出对象上的 ignorePatterns 中指定忽略文件/模式?有什么区别?
我们的src/lang 目录中有一个messages.js 文件,我试图忽略它,但目前在我们的预提交挂钩上抛出了一个lint 错误,这让我想知道这个问题以及这两个设置如何协同工作.
Parsing error: "parserOptions.project" has been set for '@typescript-eslint/parser'
The file does not match your project config: src/lang/messages.js. The file must be included in at least one of the projects provided
我认为我对这些交织的理解是错误的,因为当 eslint 运行时,我认为 parserOptions 会从 tsconfig 中获取项目规则,其中排除了 js 文件。
目前,我在我们的 eslintrc 中谈论的部分看起来像:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: path.resolve(__dirname, './tsconfig.json'),
tsconfigRootDir: __dirname,
useJSXTextNode: true,
sourceType: 'module',
ecmaFeatures: {
modules: true,
jsx: true,
},
},
ignorePatterns: ['node_modules/**', '.storybook/**', 'src/stories/**', '*.scss', '*.js'] // ignoring here works
tsconfig:
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "src/**/*.js"], // exclude here doesn't work.
package.json:
"scripts": {
"lint": "tsc --project ./tsconfig.json --noEmit && eslint --ext=jsx,ts,tsx src"
},
【问题讨论】:
-
你可能已经解决了这个问题,但我发布了一个答案,以防它帮助你,也帮助其他找到这个问题的人。
标签: javascript typescript eslint tslint