Skip to content

Commit 2ef32ff

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 fc97414 commit 2ef32ff

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/formatters/json.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* globals JSON: true */
2+
13
CSSLint.addFormatter({
24
//format information
35
id: "json",
@@ -24,10 +26,11 @@ CSSLint.addFormatter({
2426
/**
2527
* Given CSS Lint results for a file, return output for this format.
2628
* @param results {Object} with error and warning messages
29+
* @param filename {String} relative file path (Unused)
2730
* @return {String} output for results
2831
*/
2932
formatResults: function(results, filename, options) {
3033
"use strict";
31-
return options.quiet ? "" : JSON.stringify(results);
34+
return options.quiet && results.messages.length < 1 ? "" : JSON.stringify(results);
3235
}
33-
});
36+
});

tests/formatters/json.js

+10
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)