kimsagro
kimsagro

Reputation: 17365

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",
}

Upvotes: 9

Views: 4926

Answers (1)

Richard Williams
Richard Williams

Reputation: 2242

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.

Upvotes: 20

Related Questions