[英]Error while loading rule '@typescript-eslint/dot-notation'
今天跑了eslint,两个脚本
"lint-staged": "lint-staged",
"eslint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.js",
当我运行npm run eslint
// 没问题 当我运行npm run lint-staged
// 它是错误的
lint-staged 的结果;
> lint-staged
❯ Running tasks for src/**/*.tsx
✖ eslint --fix [FAILED]
◼ git add
✖ eslint --fix :
Oops! Something went wrong! :(
ESLint: 7.10.0
Error: Error while loading rule '@typescript-eslint/dot-notation': 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.
Occurred while linting /Users/***/components/BrowserInfo/Index.tsx
at Object.getParserServices (/Users/fugang/workspace/xinao/channel-desk/node_modules/_@typescript-eslint_experimental-utils@4.3.0@@typescript-eslint/experimental-utils/dist/eslint-utils/getParserServices.js:26:15)
在 package lint 阶段
发生了什么事?
"lint-staged": {
"src/**/*.tsx": [
"eslint --fix -c .eslintrc.js",
"git add"
]
},
您必须将以下配置添加到 .eslint.json 文件中
{
"parserOptions": {
...
"project": ["path/to/your/tsconfig/file"]
...
},
}
如果任何人在外面使用.eslintrc.yml
可以使用以下来解决上述问题
extends:
- airbnb-typescript
parserOptions:
project:
- tsconfig.json
PS: tsconfig.json
在根文件夹中,如果它不在根文件夹中,请更改它以匹配您的位置。
这是我最终放入 my.eslintrc.json 的内容:
module.exports = {
...
parserOptions: {
parser: '@typescript-eslint/parser',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
};
可能是项目需要./tsconfig.json
而不是tsconfig.json
。 我的 tsconfig 文件在项目根目录中。
这带来了更多错误,例如 babel 配置,所以我创建了一个.eslintignore
文件并在其中添加了这些文件:
.eslintrc.js
ios/
android/
*.config.js
这解决了我所有的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.