Skip to content

Instantly share code, notes, and snippets.

@ammonkc
Forked from guyht/gist:1012516
Created July 20, 2011 03:24
Show Gist options
  • Save ammonkc/1094266 to your computer and use it in GitHub Desktop.
Save ammonkc/1094266 to your computer and use it in GitHub Desktop.
JS: JSHint through NodeJS
#!/usr/bin/env node
/*
* Takes a list of files and runs them through JSHint
*
* Usage:
* check.js file1 file2 file3
*/
var fs = require('fs'),
jshint = require('./jshint').JSHINT,
files = [];
// Get list of files
process.argv.forEach(function(val, index, array) {
files.push(val);
});
console.log('-----------------------------------------');
for(var i=2;i<files.length;i++) {
fs.readFile(files[i], function(err, data) {
if(err) {
console.log('Error: ' + err);
return;
}
if(jshint(data.toString())) {
console.log('File ' + files[i] + ' has no errors. Congrats!');
} else {
console.log('Errors in file ' + files[i]);
console.log('');
var out = jshint.data(),
errors = out.errors;
for(var j=0;j<errors.length;j++) {
console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + errors[j].evidence);
}
// List globals
console.log('');
console.log('Globals: ');
for(j=0;j<out.globals.length;j++) {
console.log(' ' + out.globals[j]);
}
}
console.log('-----------------------------------------');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment