简体   繁体   中英

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*} ... } 

I think you need to trade brevity for specificity here:

{
...

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

...
}

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 eg

{
...

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

This is what I use to run eslint on one directory:

"lint": "node_modules/.bin/eslint --ext js --ext jsx src"

I think you can just add the test directory onto the end after src to do both. There is more information here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM