DEV Community

MariannaKhanina
MariannaKhanina

Posted on

Настройка корректной работы eslint в VS Code, когда .eslintrc.js располагается не в корневой директории.

В settings.json добавить правило

"eslint.workingDirectories": [{ 
    "directory": "/path/to/directory/with/eslintrc_file", 
    "changeProcessCWD": true 
},],
Enter fullscreen mode Exit fullscreen mode

Выдержка из доки по поводу данной настройки:

    "eslint.workingDirectories": [
      "./client", // changeProcessCWD defaults to false
      { "directory": "./server", "changeProcessCWD": true }
    ]

In the above example, client.js will be evaluated from root using root/client/.eslintrc.json,
while server.js will be evaluated from root/server using root/server/.eslintrc.json
Using changeProcessCWD causes vscode-eslint to change the current working directory of the eslint process to directory as well. This is often necessary if ESLint is used to validate relative import statements like import A from 'components/A'; which would otherwise be resolved to the workspace folder root.

Top comments (0)