为什么 vscode-eslint 使用与 ESLint 不同的 "root"?

Why does vscode-eslint use a different "root" than ESLint?

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

这是其中的一部分:

  "parserOptions": {
    "ecmaVersion": 2019,
    "project": ["./tsconfig.json", "./tsconfig.dev.json"],
    "sourceType": "module"
  },

当我 运行 我的 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 错误、dbaeumer.vscode-eslint 错误,还是我做错了什么?我该怎么做才能修复错误?

您只需将此 "eslint.workingDirectories": [{ "mode": "auto" }] 添加到您的 VS Code settings.json

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