How to configure package.json to run eslint script
So I am using eslint as a linter for my react project and I would like it to check all of my
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
eslint "**/*.js" to run on all js files in all the folders recursively (in the current folder)
You can also do:
And to ignore a folder:
eslint "**/*.js" --ignore-pattern node_modules/
Know more at eslint/command-line-interface
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.
Command Line Interface - ESLint, To run ESLint on Node.js, you must have npm installed. and/or package.json files are also used for configuration (i.e., --no-eslintrc was not specified), the package.json - create an eslintConfig property in your package.json file and define your configuration there. If there are multiple configuration files in the same directory, ESLint will only use one. The priority order is:.eslintrc.js.eslintrc.yaml.eslintrc.yml.eslintrc.json.eslintrc; package.json; Configuration Cascading and Hierarchy
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
Configuring ESLint - ESLint, sourceType - set to "script" (default) or "module" if your code is in ECMAScript To indicate the npm module to use as your parser, specify it using the parser The exact contents of your package.json depend on your project, it is the pretest script that you have to add to cause eslint to run before your unit tests (when you you use npm to run the test script, it will also run the pretest and posttest scripts if they exist).
- 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?
- @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
- ESLint always ignores files in
/bower_components/*. Documentation Edit: Ok, I realized that your answer also ignores node_modules in a child path, my bad.
- Note: This doesn't work on Windows. 😏