The project structure is as follows:

root/
  client/
  .eslintrc.js
  package.json
Copy the code

Description of the problem:

  1. Eslint does not take effect when the root directory is opened with VS Code
  2. Eslint works fine when the client directory is opened using VS Code

After reviewing various documentation, THE VS Code ESLint plugin has configuration items for this, only versions after 2.0.0 support this

eslint.workingDirectories

  • [{ “mode”: “location” }]

  • The default configuration will only look for the esLint configuration in the project directory, i.e. Root

  • [{ “mode”: “auto” }]

  • Automatically, this will automatically look for the esLint configuration file in the project folder, the dumbest configuration

    “eslint.workingDirectories”: [{ “mode”: “auto” }]

  • string[]

  • Manually configure by manually configuring the folder directory of the project

  •   "eslint.workingDirectories": [ "./client" ]
    Copy the code
  • [{ “pattern”: glob pattern }]

  • Match expression to match multiple items in a file, for example:

  •   "eslint.workingDirectories": [{ "pattern": "./packages/*/" }]
    Copy the code

We can solve the problem in the second or third way.

We went to vs Code’s setting Directories, found esLint Working Directories, and hit Edit in Setting. json

After saving, restart VS Code and the problem is resolved.

Reference Documents:

Github.com/microsoft/v…