diff --git a/index.js b/index.js index 0827449..f56aed6 100644 --- a/index.js +++ b/index.js @@ -96,7 +96,7 @@ cssLintPlugin.reporter = function(customReporter) { } if (builtInReporter) { - output = reporter.startFormat(); + output = [reporter.startFormat()]; } return through.obj( @@ -104,7 +104,7 @@ cssLintPlugin.reporter = function(customReporter) { // Only report if CSSLint was ran and errors were found if (file.csslint && !file.csslint.success) { if (builtInReporter) { - output += reporter.formatResults(file.csslint.originalReport, file.path); + output.push(reporter.formatResults(file.csslint.originalReport, file.path)); } else { reporter(file); @@ -114,10 +114,14 @@ cssLintPlugin.reporter = function(customReporter) { return cb(null, file); }, function(cb) { + var report; + if (builtInReporter) { - output += reporter.endFormat(); + output.push(reporter.endFormat()); + report = output.join(''); - gutil.log(output); + // Only print report if the report is not empty + report && gutil.log(report); } return cb(); diff --git a/test/fixtures/validCSS.css b/test/fixtures/validCSS.css index a15c877..d1e777a 100644 --- a/test/fixtures/validCSS.css +++ b/test/fixtures/validCSS.css @@ -1,3 +1,3 @@ -.foo { +.is-foo { color: red; } diff --git a/test/main.js b/test/main.js index d927726..24e8b11 100644 --- a/test/main.js +++ b/test/main.js @@ -250,7 +250,9 @@ describe('gulp-csslint', function() { stream.write(file); stream.end(); }); + }); + describe('cssLintPlugin.reporter()', function() { it('should support built-in CSSLint formatters', sinon.test(function(done) { var a = 0; @@ -284,5 +286,39 @@ describe('gulp-csslint', function() { lintStream.write(file); lintStream.end(); })); + + it('should not print empty output by built-in CSSLint formatters', sinon.test(function(done) { + var a = 0; + + var file = getFile('fixtures/validCSS.css'); + + var lintStream = cssLintPlugin(); + var reporterStream = cssLintPlugin.reporter('text'); + + sinon.stub(gutil, 'log'); + + reporterStream.on('data', function() { + ++a; + }); + lintStream.on('data', function(newFile) { + should.exist(newFile.csslint.success); + newFile.csslint.success.should.equal(true); + reporterStream.write(newFile); + }); + lintStream.once('end', function() { + reporterStream.end(); + }); + + reporterStream.once('end', function() { + a.should.equal(1); + sinon.assert.callCount(gutil.log, 0); + + gutil.log.restore(); + done(); + }); + + lintStream.write(file); + lintStream.end(); + })); }); });