ESLint only target a specific directory (eslintrc, create-react-app)

Dustwise picture Dustwise · Jan 4, 2018 · Viewed 23.8k times · Source

I have a folder structure similar to this:

/root
 .eslintrc.json
 package.json
 /someFolder
   /sub
   /sub
 /anotherFolder
 /src
   /containers
   /components
 /oneMoreFolder
   /sub
   /sub

I'm working with create-react-app and am applying airbnb rules. I have been able to run the linter in a specific folder easily from the CLI but on compile, it targets ALL folders.

I want to run the linter on compile on just the files within the /src folder.

How can I go about this? I've tried a number of solutions.

Thank you!

TL:DR How do I target just one subfolder and all of its files on compile when using eslint and create-react-app?

Answer

Jalal picture Jalal · Dec 11, 2018

inside your .eslintrc.json

{
  "rules": {
    "quotes": [ 2, "double" ]
  },

  "overrides": [
    {
      "files": [ "src/**/*.js" ],
      "rules": {
        "quotes": [ 2, "single" ]
      }
    }
  ]
}

in .eslintignore

 /someFolder
 /anotherFolder
 /oneMoreFolder