Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wildcards in npm scripts on windows

I am trying to lint all my javascript files using jshint with an npm script command.

I am running on windows and no matter what wildcard I specify I can't seem to lint more than one file.

Referencing a specific file works:

"scripts": {
    "lint": "jshint app/main.js"
}

But all of the following results in errors:

"scripts": {
    // results in Can't open app/**/*.js'
    "lint1": "jshint app/**/*.js",

    // results in Can't open app/*.js'
    "lint2": "jshint app/*.js",

    // results in Can't open app/**.js'
    "lint3": "jshint app/**.js",
}
like image 248
kimsagro Avatar asked Dec 13 '14 01:12

kimsagro


1 Answers

Although you can't use the wildcards when running jshint as a script task in npm on windows, you can work around it. By default, if jshint is passed a directory, it will search that directory recursively. So in your case you could simply do:

"script": {
  "lint": "jshint app"
}

or even

"script": {
  "lint": "jshint ."
}

This will result in all files - including those in node_modules being linted - which is probably not what you want. The easiest way to get round that is to have a file called .jshintignore in the root of your project containing the folders and scripts you don't want linted:

node_modules/
build/
dir/another_unlinted_script.js

This is then a cross-platform solution for jshint as a script task in npm.

like image 143
Richard Williams Avatar answered Sep 21 '22 03:09

Richard Williams