Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 695
Dustwise Avatar asked Jan 04 '18 00:01

Dustwise


3 Answers

inside your .eslintrc.json

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

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

in .eslintignore

 /someFolder
 /anotherFolder
 /oneMoreFolder
like image 170
Jalal Avatar answered Oct 14 '22 17:10

Jalal


You need to do something like eslint src/**/*.js[x]. If you are running a webpack build(or precommit hook) that does linting check then add it within the scripts object inside package.json.

like image 36
Hozefa Avatar answered Oct 14 '22 16:10

Hozefa


I used ignorePatterns option. It'll tell ESLint to ignore specific files and directories. It's useful when your IDE (ex. VS Code) is reporting errors in unwanted files.

{
  "ignorePatterns": ["gulpfile.js", "gulp/**/*", "webpack.config.js"]
}

You can Also use the .eslintignore file.

like image 15
Vahid Avatar answered Oct 14 '22 18:10

Vahid