Skip to content

Commit c215bc4

Browse files
committed
Output errors even with --quiet
Output results even if options.quiet is true. Adds a test to verify that this is working properly.
1 parent 94eed44 commit c215bc4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/formatters/json.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ CSSLint.addFormatter({
2525
/**
2626
* Given CSS Lint results for a file, return output for this format.
2727
* @param results {Object} with error and warning messages
28+
* @param filename {String} relative file path (Unused)
2829
* @return {String} output for results
2930
*/
3031
formatResults: function(results, filename, options) {
3132
"use strict";
32-
return options.quiet ? "" : JSON.stringify(results);
33+
return options.quiet && results.messages.length < 1 ? "" : JSON.stringify(results);
3334
}
34-
});
35+
});

tests/formatters/json.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
Assert.areEqual("", actual);
1919
},
2020

21+
"Should have output when quiet option is specified and there are errors": function() {
22+
var result = { messages: [
23+
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] },
24+
{ type: "error", line: 2, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] }
25+
], stats: [] },
26+
expected = "{\"messages\":[{\"type\":\"warning\",\"line\":1,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]},{\"type\":\"error\",\"line\":2,\"col\":1,\"message\":\"BOGUS\",\"evidence\":\"ALSO BOGUS\",\"rule\":[]}],\"stats\":[]}",
27+
actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE", quiet: "true"});
28+
Assert.areEqual(expected, actual);
29+
},
30+
2131
"File with problems should list them": function() {
2232
var result = { messages: [
2333
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: [] },

0 commit comments

Comments
 (0)