Skip to content

Instantly share code, notes, and snippets.

@johnmdonahue
Created March 8, 2012 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmdonahue/1998016 to your computer and use it in GitHub Desktop.
Save johnmdonahue/1998016 to your computer and use it in GitHub Desktop.
Attempts to add args to spawned jshint process
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
*/
// 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),
*/
// 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
*/
// 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