如何修复 eslintrc 文件与您的项目配置不匹配?

新手上路,请多包涵

在我的打字稿项目中,我使用的是 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

我怎样才能解决这个问题?

原文由 omega 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 661
1 个回答

更新您的 eslintrc.js 以包括:

ignorePatterns: [’.eslintrc.js’]

原文由 Joe Lawson 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题