为什么 vscode-eslint 使用与 ESLint 不同的“根”?

Shi*_*vam 2 eslint visual-studio-code

每次我在 Visual Studio Code 中打开项目文件夹时,每个文件的第一行都会出现错误。它找不到我的tsconfig.json文件,因为它正在查找我打开 VS Code 的目录,而不是我所在的目录eslint.json。我的根项目中有一个functions文件夹,其中包含 ESLint 配置。

这是其中的一部分:

  "parserOptions": {
    "ecmaVersion": 2019,
    "project": ["./tsconfig.json", "./tsconfig.dev.json"],
    "sourceType": "module"
  },
Run Code Online (Sandbox Code Playgroud)

当我运行 lint 命令时eslint "src/*.{ts,js}",它运行良好并显示正确的警告。这意味着 VS Code 插件dbaeumer.vscode-eslint解析配置的.eslintrc.json方式与应有的不同。

如果我将 更改project["./functions/tsconfig.json", "./functions/tsconfig.dev.json"],那么 VS Code 将停止给出错误,但是当我运行 ESLint 时,它会尝试<path/to/project>/functions/functions/tsconfig.json在函数目录中查找它两次。

这是 VS Code 的 bug、dbaeumer.vscode-eslintbug 还是我做错了什么?我可以做什么来修复该错误?

Shi*_*vam 5

"eslint.workingDirectories": [{ "mode": "auto" }]您只需将其添加到 VS Code 中即可settings.json

它应该会使错误消失,但它可能会产生意想不到的副作用。更多信息:https://marketplace.visualstudio.com/items?itemName =dbaeumer.vscode-eslint#settings-options