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.
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.
Because Create React App comes with ESLint already integrated. They use their own sharable ESLint configuration and this can be found under the eslintConfig object in package.
Note, ESLint is installed with create-react-app, so you don't need to explicitly install it. Then install the packages for Airbnb config. This command will work for Yarn or NPM.
Create a New React Project To create a new app/project using this tool, all we need to do is run the command "create-react-app" followed by the app name. After running the above command, a new folder called "my-sample-app" will get created and that would have all of our application code.
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"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With