Skip to content

Instantly share code, notes, and snippets.

@quad
Created April 23, 2013 04:58
Show Gist options
  • Save quad/5440956 to your computer and use it in GitHub Desktop.
Save quad/5440956 to your computer and use it in GitHub Desktop.
A phantomjs runner for JSHint
// PhantomJS doesn't support bind yet
Function.prototype.bind = Function.prototype.bind || function (thisp) {
var fn = this;
return function () {
return fn.apply(thisp, arguments);
};
};
(function(p) {
var fs = require('fs'),
jshintfile = p.args[0],
jsfile = p.args[1];
if (!fs.isReadable(jsfile)) {
console.log('Unreadable file.');
p.exit(true);
}
if (!p.injectJs(jshintfile)) {
console.log('Could not inject jshint.');
p.exit(true);
}
JSHINT(fs.read(jsfile));
if (JSHINT.errors.length > 0) {
JSHINT.errors.forEach(function(err) {
console.log(jsfile + ':' + err.line + ' [' + err.character + '] ' + err.reason);
});
p.exit(true);
}
p.exit(false);
}(phantom));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment