How to configure package.json to run eslint script

2019-03-12 03:08发布

问题:

So 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 inidvidually

Thanks in advance for the help

回答1:

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



回答2:

eslint . --ext .js to lint files with the .js extension 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.



回答3:

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

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

Also according to a member's comment on project's Github using . equals running on all sub directories. It seems to me that running eslint . should suffice!