Skip to content

Configuring VSCode ESLint for Subfolder Projects in Monorepos | VSCode Tutorial

Introduction

When working on a larger codebase organized into subfolders, such as in a monorepo, it's essential to configure Visual Studio Code (VSCode) correctly to ensure tools like ESLint operate properly. The challenge arises when ESLint needs to be executed in a specific subfolder context, rather than the root of the workspace. This brief guide will walk you through setting up your VSCode workspace to handle projects in subfolders, ensuring ESLint works as expected.

Step-by-Step Guide

  1. Understanding Workspace Settings: VSCode allows you to customize settings on a per-folder basis using the workspace settings. These settings override user settings and are ideal for project-specific configurations.

  2. Opening the Subfolder as a Workspace: If your project is contained within a subfolder, you can open it directly in VSCode. Go to File > Open Folder and select the subfolder. This sets the subfolder as the root of your workspace.

  3. Adjusting ESLint Configuration: If you need to work with the entire codebase and have ESLint focus on a subfolder, you can modify the ESLint settings within VSCode.

    • Open the Command Palette with Ctrl+Shift+P or Cmd+Shift+P.
    • Type Preferences: Open Settings (JSON) and select it.
    • Add or modify the eslint.workingDirectories setting to include your subfolder, like so:
      json
      "eslint.workingDirectories": [
        { "directory": "./path/to/your/subfolder", "changeProcessCWD": true }
      ]
    • Setting changeProcessCWD to true instructs VSCode to treat the specified directory as the current working directory for ESLint operations.
  4. Restarting ESLint Server: After changing settings, it may be necessary to restart the ESLint server within VSCode for changes to take effect.

    • Open the Command Palette again.
    • Type and select ESLint: Restart ESLint Server.

Conclusion

By configuring your VSCode workspace settings correctly, you can ensure that ESLint and other tools work as expected, even in complex projects with multiple subfolders. Remember that the right setup helps maintain code quality and consistency across your project, making your development process smoother and more efficient.