I have created a .env
file in my project root but I'm new to working with environments / variables and so I'm unsure how to integrate the file so I can override the stock, non-ejected react-app eslint settings.
// My .env file has just this
EXTEND_ESLINT = "true"
The c-r-a docs explain what the variable is, but not now to set it to true. Also, the section on 'Extending the ESLint config' is helpful only for once the var is set to true.
// stock create-react-app package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
In the project root directory, you can create the
.env
file withEXTEND_ESLINT
set totrue
so as to extend the ESLint config:Also this also works:
Tried with create-react-app version 3.4.1, the latest version at the time of writing.
As an example, you can override the
no-unused-vars
rule in thepackage.json
, as below:Now run the linter, e.g.,
npm run lint
, you will not see any warning even if you have assigned a value to a variable but never used it in your application, kind of warning which you would normally see by the default settings. For example:Note:
npm start
andnpm run build
, etc., will also honour the extended rules.By the way, the original
package.json
looks like this:Note: Another way to configure ESLint is to remove the
eslintConfig
entry from thepackage.json
file and create.eslintrc
or.eslintrc.json
in the project root directory as below:[Update] If you find that react-scripts is not honouring your change to the ESLint rules, it is most likely caused by the cache. It is an open issue of the project at the moment. You can manually disable the cache in
node_modules/react-scripts/config/webpack.config.js
like below:Note that this workaround would only be for your local development. You don't need to do anything for your build pipeline most likely, as the pipeline usually builds from scratch; so there is no such cache issue out there.