I have a project that has a following structure:
modules
│ ├── client
│ ├── .eslintrc.json
│ └── backend
│ ├── .eslintrc.json
...
The problem is, that when I open the project in the parent folder of modules (project's root folder), Eslint instance running inside of VS Code is unable to resolve any import path, aside from those pointing to node_modules. If I run Eslint inside client those paths are resolved without a problem.
I have found that if you have your Eslint config in javascript you are able to use __dirname and this I assume should combat this issue, but those features are not available to me in JSON. Is there any alternative to this inside JSON? Or will I have to remake those configs into javascript?
Thanks in advance.
I solved this with the eslint.workingDirectories setting.
You can list all directories individually, but I used the pattern option like:
"eslint.workingDirectories": [
{ "pattern": "./packages/*/" }
]
VS Code may have problems understanding in which folders ESLint needs to run.
This can be fixed by going to your VS Code Settings (CMD + , on Mac), switching to Workspace and finding eslint.workingDirectories and setting it to: [{ "mode": "auto" }].
This approach has some caveats and there are alternatives, see more here: https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint#settings-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With