Permalink
Browse files

Report unused variables in lint task. Fixes #164.

  • Loading branch information...
1 parent fd00ab7 commit 5a2d098d8f3f260ae1a4d86388edce3e20e1f37b @scottgonzalez scottgonzalez committed with Apr 28, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 tasks/lint.js
View
10 tasks/lint.js
@@ -121,6 +121,7 @@ module.exports = function(grunt) {
var placeholderregex = new RegExp(tabstr, 'g');
// Lint.
var result = jshint(src, options || {}, globals || {});
+ var data = jshint.data();
// Attempt to work around JSHint erroneously reporting bugs.
// if (!result) {
// // Filter out errors that shouldn't be reported.
@@ -130,7 +131,7 @@ module.exports = function(grunt) {
// // If no errors are left, JSHint actually succeeded.
// result = jshint.errors.length === 0;
// }
- if (result) {
+ if (result && !data.unused) {
// Success!
grunt.verbose.ok();
} else {
@@ -171,6 +172,13 @@ module.exports = function(grunt) {
grunt.log.error(e.reason);
}
});
+ // Iterate over all unused variables
+ (data.unused || []).forEach(function(u) {
+ // Manually increment errorcount since we're not using grunt.log.error().
+ grunt.fail.errorcount++;
+ var pos = '['.red + ('L' + u.line).yellow + ']'.red;
+ grunt.log.writeln(pos + ' unused variable ' + u.name.yellow);
+ });
grunt.log.writeln();
}
});

0 comments on commit 5a2d098

Please sign in to comment.