antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
3.81k stars 426 forks source link

vscode + ts + monorepo - issues with resolving `parserOptions` files in IDE (but not cli) #463

Closed timfee closed 5 months ago

timfee commented 5 months ago

Describe the bug

When I have several eslint instances in my monorepo that reference a common package, Visual Studio seems to get "stuck" in resolving the project directory to the first path I open in a session, and uses that path to validate all other packages.

I tried "auto" as well as explicitly listing workingDirectories in my config file, and have used the nightly version of ESLint with flat-file support, as well as the prod version with the experimental enable flag set to true.

Repro

https://github.com/antfu/eslint-config/assets/3246342/74264639-f6ca-4739-881e-0879dbac3eee

  1. Open the workspace root in VSCode then open a file in a sub-directory that ESLint would validate.
  2. Observe it works fine.
  3. Open a file in a different sub-directory and observe that the resolved project parser is pointing to the cwd of the file in step 1.
  4. Run turbo lint from the workspace root and observe no errors.

Not sure if this is an issue with the IDE, or if maybe my strategy to implement this cleanly is wrong, but wanted to share in case the issue was something here. (Cross-posted to https://github.com/microsoft/vscode-eslint/issues/1840 in case it was the extension)

Reproduction

https://github.com/timfee/eslint-repro

System Info

System:
    OS: macOS 14.4.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 12.12 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.1 - ~/.local/share/asdf/installs/nodejs/21.6.1/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.local/share/asdf/plugins/nodejs/shims/npm
    pnpm: 8.15.2 - ~/.local/share/asdf/installs/pnpm/8.15.2/bin/pnpm
    bun: 1.1.4 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 123.0.6312.87
    Safari: 17.4.1

Used Package Manager

pnpm

Validations

thenbe commented 5 months ago

See if the "vscode eslint extension" logs can help you track this down. You might be able to access them through the command palette. Otherwise they're accessible through that bottom panel somewhere (the one with ports, output, terminal, ...). I'd also look to see if there is a verbose mode you can toggle for the eslint extension.

Either way, if you're seeing the issue only through the vscode (while usage through the cli is as expected) then it's likely to be an issue with the extension/its configuration.

seems to get "stuck" in resolving the project directory to the first path I open in a session, and uses that path to validate all other packages

Can this help give you more control over the faulty auto behavior? https://github.com/microsoft/vscode-eslint/blob/553e632fb4cf073fce1549fb6c3c1b5140a52ebb/README.md?plain=1#L262

timfee commented 5 months ago

Thank you for the note :)

Yeah, I've tried the different tweaks at the extension level - leading me to believe it may be something weird with the extension and/or latest ESLint.

I wasn't sure if I was doing something wrong with this config.

For example, I wanted to have an eslint for typescript, one for Nextjs apps, and one generic node - and to have them extendable and stackable (sort of like the default create-turbo setup), so this is the meta context behind this quest :)

timfee commented 5 months ago

Ah, so I found the culprit:

When I specify my project directory this way, it works:

  typescript: {
-      tsconfigPath: "./tsconfig.json",
+      parserOptions: {
+        project: "./tsconfig.json",
+      },
    },