Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ cssLintPlugin.reporter = function(customReporter) {
}

if (builtInReporter) {
output = reporter.startFormat();
output = [reporter.startFormat()];
}

return through.obj(
function(file, enc, cb) {
// 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);
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/validCSS.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.foo {
.is-foo {
color: red;
}
36 changes: 36 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}));
});
});