使用 Typescript 时,为什么 ESLint 尝试在自己的配置文件上运行?

Dav*_*ein 11 typescript eslint typescript-eslint

.eslintignore就在旁边eslintrc.js

忽略的原因很简单:

.eslintrc.js
dist/*
node_modules/*
out-tsc/*
Run Code Online (Sandbox Code Playgroud)

但是,当我进入时,eslintrc.js我收到此错误:

Parsing error: ESLint was configured to run on `<tsconfigRootDir>/.eslintrc.js` using `parserOptions.project`: <tsconfigRootDir>/../../../../../../users/dstein/repositories/social-experiment/packages/site/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file
Run Code Online (Sandbox Code Playgroud)

不出所料,它链接到的文章说,.eslintignore如果您不想对错误所在的文件进行 lint 检测,则可以使用该方法。同时,我的 TS 配置没有说要包含任何js文件。

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "lib": ["es2017", "dom"],
    "strict": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "outDir": "out-tsc",
    "sourceMap": true,
    "inlineSources": true,
    "rootDir": "./",
    "incremental": true
  },
  "include": ["**/*.ts"],
}
Run Code Online (Sandbox Code Playgroud)

真的很困惑为什么 TS Config 说只包含ts文件会有 ESLint,它被配置为使用parserOptions.project

ESLint 配置相当简单(我将删除所有规则以节省阅读时间):

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ['./tsconfig.json'],
  },
  plugins: ['@typescript-eslint'],
  env: {
    es6: true,
    browser: true,
  },
  extends: [
    '@open-wc',
    'eslint:recommended',
    'plugin:import/recommended',
    'prettier',
  ],
  rules: {},
};

Run Code Online (Sandbox Code Playgroud)

Jos*_*odu 0

将 eslint 配置文件添加到配置本身要忽略的文件列表中。

像这样的东西:

ignorePatterns: ['dist', '.eslintrc.js', 'postcss.config.js'],
Run Code Online (Sandbox Code Playgroud)