Skip to content

Commit

Permalink
Execute the reporter once. Fixes gruntjsGH-54. Closes gruntjsGH-55.
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer authored and shama committed May 20, 2013
1 parent 698eb3a commit a05b0d5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.5.3:
date: 2013-05-19
changes:
- Performance: Execute the reporter once rather than per file.
v0.5.2:
date: 2013-05-18
changes:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ grunt.initConfig({

## Release History

* 2013-05-19   v0.5.3   [object Object]
* 2013-05-18   v0.5.2   Fix printing too many erroneous ignored file errors.
* 2013-05-17   v0.5.1   Fix for when only 1 file is lint free.
* 2013-05-17   v0.5.0   Bump to jshint 2.0. Add support for .jshintignore files and ignores option Add support for extensions option. Add support for custom reporters and output report to a file.
Expand All @@ -183,4 +184,4 @@ grunt.initConfig({

Task submitted by ["Cowboy" Ben Alman](http://benalman.com/)

*This file was generated on Sat May 18 2013 20:24:33.*
*This file was generated on Sun May 19 2013 20:55:24.*
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-jshint",
"description": "Validate files with JSHint.",
"version": "0.5.2",
"version": "0.5.3",
"homepage": "https://github.com/gruntjs/grunt-contrib-jshint",
"author": {
"name": "Grunt Team",
Expand Down
8 changes: 2 additions & 6 deletions tasks/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ module.exports = function(grunt) {
// Fail task if errors were logged except if force was set.
failed = force;
} else {
if (jshint.usingGruntReporter === true) {
if (data.length < 1) {
grunt.log.error('0 files linted. Please check your ignored files.');
} else {
grunt.log.ok(data.length + ' file' + (data.length === 1 ? '' : 's') + ' lint free.');
}
if (jshint.usingGruntReporter === true && data.length > 0) {
grunt.log.ok(data.length + ' file' + (data.length === 1 ? '' : 's') + ' lint free.');
}
}

Expand Down
25 changes: 11 additions & 14 deletions tasks/lib/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports.init = function(grunt) {
exports.reporter = function(results, data) {
// Dont report empty data as its an ignored file
if (data.length < 1) {
grunt.log.error('0 files linted. Please check your ignored files.');
return;
}

Expand Down Expand Up @@ -194,22 +195,18 @@ exports.init = function(grunt) {
cliOptions.config = options;
grunt.verbose.writeflags(options, 'JSHint options');

// Run JSHint on each file and collect results/data
// Run JSHint on all file and collect results/data
var allResults = [];
var allData = [];
grunt.util.async.forEach(files, function(filepath, next) {
var cliopts = grunt.util._.clone(cliOptions);
cliopts.args = [filepath];
cliopts.reporter = function(results, data) {
reporter(results, data);
allResults = allResults.concat(results);
allData = allData.concat(data);
next();
};
jshintcli.run(cliopts);
}, function() {
done(allResults, allData);
});
var cliopts = grunt.util._.clone(cliOptions);
cliopts.args = files;
cliopts.reporter = function(results, data) {
reporter(results, data);
allResults = allResults.concat(results);
allData = allData.concat(data);
};
jshintcli.run(cliopts);
done(allResults, allData);
};

return exports;
Expand Down
15 changes: 15 additions & 0 deletions test/jshint_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,19 @@ exports.jshint = {
test.done();
});
},
singleReportCall: function(test) {
test.expect(2);

// stub jshint.reporter
var reporterCallCount = 0;
var _report = jshint.reporter;
jshint.reporter = function() { reporterCallCount++; };

var files = [path.join(fixtures, 'dontlint.txt'), path.join(fixtures, 'lint.txt')];
jshint.lint(files, {}, function(results, data) {
test.equal(data.length, 1, 'Should not have linted a file listed in the .jshintignore.');
test.equal(reporterCallCount, 1, 'Should have called the reporter once.');
test.done();
});
}
};

0 comments on commit a05b0d5

Please sign in to comment.