Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override eslint settings in non-ejected create-react-app?

I've found a ton of "solutions" for this, ranging from simple package.json additions to custom hack modules, but none worked for me.

I simply want to override the eslint settings for an out-of-the-box, NON ejected create-react-app.

Namely, the rule "no-unused-vars".

I'm using Visual Studio Code.

like image 922
Kirk Ross Avatar asked Feb 18 '20 21:02

Kirk Ross


People also ask

How do I disable ESLint create-react-app?

As of react-scripts v4. 0.2, you can now opt out of ESLint with an environment variable. You can do this by adding it to your . env file, or by prefixing your scripts in your package.

Do you need to install ESLint With create-react-app?

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.


2 Answers

I seem to have fixed this accidentally just trying combinations of things I found online. This seems to have worked.

1) I created a .env file in the project root (where the package.json file is). In it I have:

// .env file

EXTEND_ESLINT = true

2) Then I created a .eslintrc file (no extension) in my project root and added this:

// .eslintrc file (no extension)
{
  "extends": [
    "react-app"
  ],
  "rules": {
    "no-unused-vars": "off"
  }
}
like image 180
Kirk Ross Avatar answered Oct 17 '22 22:10

Kirk Ross


The library now supports extending the pre-defined ESLint rules natively, see the relevant docs.


The gist of it is that you will have to set the EXTEND_ESLINT environment variable, and then add your own ESLint config to the project root, optionally extending create-react-app's:

{
  "eslintConfig": {
    "extends": ["react-app"],
    "overrides": [
      {
        "files": ["**/*.js"],
        "rules": {
          "no-unused-vars": "warn"
        }
      }
    ]
  }
}
like image 27
TimoStaudinger Avatar answered Oct 17 '22 21:10

TimoStaudinger