Search code examples
javascriptreactjsvisual-studio-codecreate-react-appeslint

create-react-app subfolder projects do not lint


Projects bootstrapped with create-react-app within subfolders do not lint. However, if I open the project subfolder as root in VSCode (pictured below), or setup a new create-react-app project at root, linting works fine.

enter image description here

This occurs with both standard and ejected create-react-app projects.

Ideally without ejecting, how can I make create-react-app's linting work with subfolder projects?

I'm using create-react-app v3.1.1, VSCode August 2019 and Windows 10.


Solution

  • The VSCode ESLint Extension includes settings for specifying working directories:

    an array for working directories to be used. ESLint resolves configuration files (e.g. eslintrc) relative to a working directory. This new settings allows users to control which working directory is used for which files.

    Therefore, in this case, adding the following to the Workspace settings.json file solves the issue:

    {
        "eslint.workingDirectories": [
            "./client"
        ]
    }