From b9c31a56aa53cb332d47895c1c1c27fd1fda9db3 Mon Sep 17 00:00:00 2001 From: Abhishek Dev Date: Sun, 14 Feb 2016 20:23:27 -0500 Subject: [PATCH 1/2] Do not print empty built-in reports - This avoid irregular breaks in the console logs for successful but empty report formats (like text and compact). XML reports would print as XML syntax requires root tags --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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(); From fffca51bcbc2621f915c5f7368c686a12a8cd032 Mon Sep 17 00:00:00 2001 From: abhishekdev Date: Sun, 14 Feb 2016 20:26:55 -0500 Subject: [PATCH 2/2] Add test to check no outputs are printed for empty reports Fixes #39 --- test/fixtures/validCSS.css | 2 +- test/main.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) 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(); + })); }); });