ESLint Configuration for Monorepo in VSCode

2024-08-27 hit count image

Let's see how to configure ESLint in VSCode when developing Monorepo projects.

Outline

Because multiple packages are managed in a single repository in a Monorepo environment, each package sometimes requires a separate ESLint configuratoin. At this time, It is important to determine which directory ESLint is based on.

In this blog post, I will introduce how to set the Current Working Directory(CWD) of ESLint in Visual Studio Code(VSCode) when developing Monorepo projects.

Current working directory in VSCode

If you configure nothing special in VSCode, ESLint will work based on the ESLint configuration file in the root folder. However, in Monorepo projects, each project may have its own ESLint configuration file.

In this case, if you set the Current Working Directory(CWD) of ESLint in VSCode, ESLint will work based on that directory.

Modify .vscode/settings.json file

The following is how to set the Current Working Directory(CWD) of ESLint in VSCode.

  1. Configure the mode
{
  ...
  "eslint.workingDirectories": [{ "mode": "auto" }]
}

If you set it like this, VSCode will automatically find the directory with the ESLint configuration file and set it as the CWD.

  1. Configure the pattern
{
  ...
  "eslint.workingDirectories": [{ "pattern": "./packages/*/" }]
}

You can also set the directory to be the CWD with a Glob pattern.

  1. Configure the directories
{
  ...
  "eslint.workingDirectories": ["./packages/package1", "./packages/package2"]
}

You can also specify specific directories as an array like this.

Completed

Done! We’ve seen how to set the Current Working Directory(CWD) of ESLint in VSCode when developing Monorepo projects.

In my case, I’m using "mode": "auto". If there are no special problems, I recommend using this setting.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts