Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package.json and Eslint glob extension

My package.json is below. How do I update it so that eslint runs on:

src and test directories

for

.js and .jsx files only? Right now the * wild card is including .json which I don't want.

package.json

{
...

"lint": "eslint {src/**/*.js*,test/**/*.js*}

...
}
like image 495
Sebastian Patten Avatar asked Mar 08 '19 19:03

Sebastian Patten


2 Answers

You can read in eslint documentation:

Please note that when passing a glob as a parameter, it will be expanded by your shell. The results of the expansion can vary depending on your shell, and its configuration. If you want to use node glob syntax, you have to quote your parameter (using double quotes if you need it to run in Windows), as follows:

So it would be advisable to use double quotes. Once you use double quotes (which need to be escaped inside json string) you can slightly modify your pattern e.g.

{
...

"lint": "eslint \"{src,test}/**/*.{js,jsx}\""

...
}

Test using globster.xyz (globster.xyz require / at the beginning but eslint doesn't, not sure why...)

There is usually more than one way to achieve what you want but I think this would be the most concise.

like image 64
Domajno Avatar answered Sep 28 '22 04:09

Domajno


I think you need to trade brevity for specificity here:

{
...

"lint": "eslint {src/**/*.js,src/**/*.jsx,test/**/*.js,test/**/*.jsx}"

...
}
like image 27
Meg Avatar answered Sep 28 '22 02:09

Meg