Shivam
Shivam

Reputation: 1424

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

Everytime I open my project folder in Visual Studio Code, I get an error on the first line of each file. It cannot find my tsconfig.json file because it is looking in the directory I opened VS Code, not where my eslint.json is. I have a functions folder in my root project where the ESLint config is.

Here is part of it:

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

When I run my lint command eslint "src/*.{ts,js}", it works perfectly and shows the correct warnings. This means that the VS Code plugin dbaeumer.vscode-eslint parses the .eslintrc.json config differently than what it should.

If I change the project to ["./functions/tsconfig.json", "./functions/tsconfig.dev.json"], then VS Code stops giving the error, but when I run ESLint, it tries to find it in <path/to/project>/functions/functions/tsconfig.json going in the functions directory twice.

Is this a VS Code bug, a dbaeumer.vscode-eslint bug, or am I doing something wrong? What can I do to fix the error?

Upvotes: 3

Views: 2574

Answers (1)

Shivam
Shivam

Reputation: 1424

You can just add this "eslint.workingDirectories": [{ "mode": "auto" }] to your VS Code settings.json.

It should make the error go away, but it can have unintended side effects. More Info: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint#settings-options

Upvotes: 8

Related Questions