Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created April 28, 2011 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slackorama/947059 to your computer and use it in GitHub Desktop.
Save slackorama/947059 to your computer and use it in GitHub Desktop.
// blame_comma.js -- loop through the files passed in and see who has commas
// in them
// find ../htdocs/js/ECM -type f -name "*.js" -print | xargs java -classpath /usr/share/yuicompressor-2.4.2/lib/rhino-1.6R7.jar org.mozilla.javascript.tools.shell.Main blame_comma.js
load('fulljslint.js');
load('runtime.js');
(function(args) {
var bad_files = {};
for (var i = 0; i < args.length; i++) {
var file = args[i],
js = readFile(file);
var success = JSLINT(js, {
browser : true,
undef : true,
newcap : false,
// white : true,
indent : 4,
predef: ["Ext","ECM","ActiveXObject","window","TestCase","document","assertTrue","sinon","gt"]
});
if (!success) {
var errors = JSLINT.errors;
for (var j=0;j<errors.length;j++) {
var e = errors[j];
if (e && e.reason && e.reason.match(/Extra comma/)) {
var cmd = 'git blame -L' + e.line + ','+e.line + ' -- ' + file;
var output = runtime.exec( cmd );
if (!bad_files[file]) {
bad_files[file] = [];
}
bad_files[file].push(output);
}
}
}
}
for (var key in bad_files) {
if (bad_files.hasOwnProperty(key)) {
print("\n" + key);
var errors = bad_files[key];
for (var i = 0; i<errors.length;i++) {
print(errors[i]);
}
}
}
})(arguments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment