109

I am using eslint as a linter for my react project and I would like it to check all of my .js files.

I am able to do this through the script:

"lint": "eslint back/*.js && eslint backTest/*.js && eslint front/actions/*.js"

how can I get it to examine every .js file recursively, something like:

"lint": "eslint -r *.js"

This would save me having to type out each file individually.

starball
  • 20,030
  • 7
  • 43
  • 238
Sam Houston
  • 3,413
  • 2
  • 30
  • 46

4 Answers4

137

eslint "**/*.js" to run on all js files in all the folders recursively (in the current folder)

You can also do: AnyFolder/**/*.js

And to ignore a folder: eslint "**/*.js" --ignore-pattern node_modules/

Know more at eslint/command-line-interface

Robin Wieruch
  • 14,900
  • 10
  • 82
  • 107
  • I have setup eslint using tern in my eclipse oxygen. It is linting all the files, I have to set it up to only lint *.js files. What can be done here? – Nikita Dhiman Sep 27 '17 at 14:17
  • @Colin @Hadrian Doesn't eslint ONLY parse *.js files by default? Also reading docs if you add `.` it suffices to go through all sub-trees looking for js files – Saba Ahang May 29 '18 at 13:37
  • 1
    ESLint always ignores files in `/node_modules/*` and `/bower_components/*`. [Documentation](https://eslint.org/docs/user-guide/configuring#eslintignore) **Edit:** Ok, I realized that your answer also ignores node_modules in a child path, my bad. – zypA13510 Sep 04 '18 at 01:58
69

eslint . --ext .js to lint files with the .js extension.

The . targets files in the current directory and all subdirectories.

To include other file extensions, eslint . --ext .js,.jsx or eslint . --ext .js --ext .jsx.

The eslint documentation covers this option.

TranBrian10
  • 830
  • 6
  • 8
5

To add to TranBrian10's solution, I installed eslint locally, so calling eslint in the terminal results in a command not found error.

I was able to get around this by using npx eslint instead:

`eslint . --ext .js` -> `npx eslint . --ext .js`

And as GollyJer noted, this won't work for Windows due to the . syntax

Mark Thompson
  • 448
  • 5
  • 7
3

I'm not sure if the accepted answer is outdated, but by looking at the docs,

By default, it uses .js as the only file extension.

Also, according to a member's comment on the project's Github, using . equals running in all subdirectories. It seems to me that running eslint . should suffice (though it doesn't cover the new ES Module .mjs files).

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
Saba Ahang
  • 578
  • 9
  • 24