Created
March 8, 2012 02:01
-
-
Save johnmdonahue/1998016 to your computer and use it in GitHub Desktop.
Attempts to add args to spawned jshint process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (files) { | |
var args = files && files.length > 0 ? files : ["."], | |
spawn = require('child_process').spawn, | |
cmd = spawn("jshint", args.concat(["--config .jshintrc", "--show-non-errors"])); | |
function write(data) { | |
process.stdout.write(new Buffer(data).toString("utf-8")); | |
} | |
cmd.stdout.on('data', write); | |
cmd.stderr.on('data', write); | |
}; | |
/* Outputs: | |
196 errors | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Try to hardcode the first arg. At least it is now picking up the --show-non-errors | |
module.exports = function (files) { | |
var args = files && files.length > 0 ? files : ["."], | |
spawn = require('child_process').spawn, | |
cmd = spawn("jshint", [".", "--config .jshintrc", "--show-non-errors"])); | |
function write(data) { | |
process.stdout.write(new Buffer(data).toString("utf-8")); | |
} | |
cmd.stdout.on('data', write); | |
cmd.stderr.on('data', write); | |
}; | |
/* Outputs | |
196 errors | |
build/lint.js : | |
Unused Variables: | |
args(1), | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Try cwd + jshintrc path | |
module.exports = function (files) { | |
var args = files && files.length > 0 ? files : ["."], | |
path = require('path'), | |
spawn = require('child_process').spawn, | |
cmd = spawn("jshint", args.concat([("--config " + path.join(process.cwd(), '.jshintrc')), "--show-non-errors"])); | |
function write(data) { | |
process.stdout.write(new Buffer(data).toString("utf-8")); | |
} | |
cmd.stdout.on('data', write); | |
cmd.stderr.on('data', write); | |
}; | |
/* Outputs: | |
196 errors | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Try child_process.exec instead... Success | |
module.exports = function (files) { | |
var args = files && files.length > 0 ? files : ["."], | |
exec = require('child_process').exec, | |
opts = args.concat(["--config .jshintrc", "--show-non-errors"]).join(' '), | |
cmd = exec("jshint " + opts); | |
function write(data) { | |
process.stdout.write(new Buffer(data).toString("utf-8")); | |
} | |
cmd.stdout.on('data', write); | |
cmd.stderr.on('data', write); | |
}; | |
/* All clear */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment