I have followed this guide to extend my ESLint config.
https://create-react-app.dev/docs/setting-up-your-editor/#experimental-extending-the-eslint-config
The documentation states that Note that any rules set to "error" will stop the project from building
. I have added a .env
file with EXTEND_ESLINT=true
in the same folder as my package.json
file.
https://create-react-app.dev/docs/advanced-configuration/
As soon as this file was added I stopped getting warning from the command npm run build
, even when using the default values in package.json:
"eslintConfig": {
"extends": "react-app"
},
If I set .env
file to EXTEND_ESLINT=false
the warnings start to show up again.
The reason for doing it in the first place is because I want to add the no-multiple-empty-lines
rule like this:
"eslintConfig": {
"extends": [ "react-app" ],
"rules": {
"no-multiple-empty-lines": [
"error",
{
"max": 1,
"maxEOF": 0,
"maxBOF": 0
}
]
}
},
https://eslint.org/docs/rules/no-multiple-empty-lines
I think the config is correct because when I add this rule the following command will show expected result:
npx eslint . --ext .js,.jsx,.ts,.tsx
Before config change:
After config change:
Reading up on the .env
file it says that npm run build
will read files in the following order: .env.production.local, .env.production, .env.local, .env
. Since I only have .env
it should pick it up. Documentation also states this above EXTEND_ESLINT
- You do not need to declare REACT_APP_ before the below variables as you would with custom environment variables.
I have read this thread as well but I can't see where I wen't wrong:
How is ESLint integrated into Create React App?
If I edit the scripts
section in package.json
to "build": "set EXTEND_ESLINT=true && react-scripts build",
I will get the normal warnings but my added rule wont be executed anyway.