Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure package.json to run eslint script

People also ask

How do I add ESLint rules to package json?

Just simply add the key “eslintConfig” config on your package. json and start adding your eslint rules.

How do I run ESLint in node js?

First, initialize a Node. js project. Now, install the eslint npm package. In order to initialize an ESLint configuration, let us run the command.

How do I configure ESLint?

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 "**/*.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


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.


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


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