How to configure package.json to run eslint script

eslint verbose
eslint plugins
eslint-watch
install eslint:recommended
eslint vscode
eslint airbnb
eslint rules
create eslint-config

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

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

Why (and how) to use eslint in your project, With this setup, configure eslint to run automatically before your tests by changing your package.json to have a pretest script. It should look similar to this: There are two primary ways to configure ESLint: Configuration Comments - use JavaScript comments to embed configuration information directly into a file. Configuration Files - use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories.

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 .mjs files).

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).

Configuring ESLint, Configuration Files - use a JavaScript, JSON or YAML file to specify file or an eslintConfig field in a package.json file, both of which ESLint will look for and Globals - the additional global variables your script accesses during execution. This can be in the form of an .eslintrc file or an eslintConfig field in a package.json file, both of which ESLint will look for and read automatically, or you can specify a configuration file on the command line. There are several pieces of information that can be configured: Environments - which environments your script is designed to run in

Setting up ESLINT in your JavaScript Project with VS Code, Configuration Files - use a JavaScript, JSON or YAML file to specify configuration file or an eslintConfig field in a package.json file, both of which ESLint will look for and Environments - which environments your script is designed to run in. The above steps will automatically set up an ESLint configuration and install the necessary dependencies for you. If you want to set up the config manually, run the following command: npm install--save-dev eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node Then, add this to your .eslintrc

Helpers and tips for npm run scripts, steps: create a javascript project. install eslint as an extension in your VS Code Editor. Install eslint as a global package using npm. initialize eslint in your javascript project. modify your eslint configuration file in your project. ESLint uses Espree for JavaScript parsing. ESLint uses an AST to evaluate patterns in code. ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime. Installation and Usage. Prerequisites: Node.js (^8.10.0, ^10.13.0, or >=11.10.1) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)

Comments
  • 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 /node_modules/* and /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. 😏