简体   繁体   English

加载规则“@typescript-eslint/dot-notation”时出错

[英]Error while loading rule '@typescript-eslint/dot-notation'

Today I run eslint,two script今天跑了eslint,两个脚本

 "lint-staged": "lint-staged",
 "eslint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.js",

When I run npm run eslint // it's ok When I run npm run lint-staged // it's wrong当我运行npm run eslint // 没问题 当我运行npm run lint-staged // 它是错误的

lint-staged's result; 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)

In package lint-staged在 package lint 阶段

What happend?发生了什么事?

"lint-staged": {
    "src/**/*.tsx": [
      "eslint --fix -c .eslintrc.js",
      "git add"
    ]
  },

You have to add the following config to your .eslint.json file您必须将以下配置添加到 .eslint.json 文件中

{
    "parserOptions": {
        ...
        "project": ["path/to/your/tsconfig/file"]
        ...
    },
}

In case anyone outhere using .eslintrc.yml can use following to fix above issue如果任何人在外面使用.eslintrc.yml可以使用以下来解决上述问题

extends:
  - airbnb-typescript
parserOptions:
  project:
    - tsconfig.json

PS: tsconfig.json is in root folder, change it to match your location in case its not in root folder. PS: tsconfig.json在根文件夹中,如果它不在根文件夹中,请更改它以匹配您的位置。

This is what I ended up putting in my.eslintrc.json:这是我最终放入 my.eslintrc.json 的内容:

module.exports = {
  ...
  parserOptions: {
    parser: '@typescript-eslint/parser',
    project: './tsconfig.json',
    tsconfigRootDir: __dirname,
  },
};

It may have been that the project needed to be ./tsconfig.json instead of tsconfig.json .可能是项目需要./tsconfig.json而不是tsconfig.json My tsconfig file is in the project root.我的 tsconfig 文件在项目根目录中。

And this brought up some more errors linting things like babel config so I created an .eslintignore file and added those in there:这带来了更多错误,例如 babel 配置,所以我创建了一个.eslintignore文件并在其中添加了这些文件:

.eslintrc.js
ios/
android/
*.config.js

This solved all my issues.这解决了我所有的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM