From 73098e54e62fa8dda898343791b24d509993d30d Mon Sep 17 00:00:00 2001 From: Eric Wendelin Date: Sat, 15 Oct 2011 12:47:16 -0600 Subject: [PATCH] Distinguishing between warnings and errors in compact formatter fixing issue #152 --- src/formatters/compact.js | 13 +++++++++++-- tests/formatters/compact.js | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/formatters/compact.js b/src/formatters/compact.js index 2bcc31f8..735d20e8 100644 --- a/src/formatters/compact.js +++ b/src/formatters/compact.js @@ -32,15 +32,24 @@ CSSLint.addFormatter({ output = ""; options = options || {}; + /** + * Capitalize and return given string. + * @param str {String} to capitalize + * @return {String} capitalized + */ + var capitalize = function(str) { + return str.charAt(0).toUpperCase() + str.slice(1); + }; + if (messages.length === 0) { return options.quiet ? "" : filename + ": Lint Free!"; } messages.forEach(function(message, i) { if (message.rollup) { - output += filename + ": " + message.message + "\n"; + output += capitalize(message.type) + ": " + filename + ": " + message.message + "\n"; } else { - output += filename + ": " + "line " + message.line + + output += capitalize(message.type) + ": " + filename + ": " + "line " + message.line + ", col " + message.col + ", " + message.message + "\n"; } }); diff --git a/tests/formatters/compact.js b/tests/formatters/compact.js index 49b15ca2..bcbace97 100644 --- a/tests/formatters/compact.js +++ b/tests/formatters/compact.js @@ -20,24 +20,24 @@ "File with problems should list them": function() { var result = { messages: [ - { type: 'warning', line: 1, col: 1, message: 'BOGUS WARNING', evidence: 'BOGUS', rule: [] }, - { type: 'error', line: 2, col: 1, message: 'BOGUS ERROR', evidence: 'BOGUS', rule: [] } + { type: 'error', line: 2, col: 1, message: 'BOGUS ERROR', evidence: 'BOGUS', rule: [] }, + { type: 'warning', line: 1, col: 1, message: 'BOGUS WARNING', evidence: 'BOGUS', rule: [] } ], stats: [] }, - error1 = "FILE: line 1, col 1, BOGUS WARNING\n", - error2 = "FILE: line 2, col 1, BOGUS ERROR\n", - expected = error1 + error2, - actual = CSSLint.getFormatter("compact").formatResults(result, "FILE"); + err = "Error: path/to/FILE: line 2, col 1, BOGUS ERROR\n", + warning = "Warning: path/to/FILE: line 1, col 1, BOGUS WARNING\n", + expected = err + warning, + actual = CSSLint.getFormatter("compact").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE"}); Assert.areEqual(expected, actual); }, "Should output relative file paths": function() { var result = { messages: [ - { type: 'warning', line: 1, col: 1, message: 'BOGUS WARNING', evidence: 'BOGUS', rule: [] }, - { type: 'error', line: 2, col: 1, message: 'BOGUS ERROR', evidence: 'BOGUS', rule: [] } + { type: 'error', line: 2, col: 1, message: 'BOGUS ERROR', evidence: 'BOGUS', rule: [] }, + { type: 'warning', line: 1, col: 1, message: 'BOGUS WARNING', evidence: 'BOGUS', rule: [] } ], stats: [] }, - error1 = "path/to/FILE: line 1, col 1, BOGUS WARNING\n", - error2 = "path/to/FILE: line 2, col 1, BOGUS ERROR\n", - expected = error1 + error2, + err = "Error: path/to/FILE: line 2, col 1, BOGUS ERROR\n", + warning = "Warning: path/to/FILE: line 1, col 1, BOGUS WARNING\n", + expected = err + warning, actual = CSSLint.getFormatter("compact").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE"}); Assert.areEqual(expected, actual); }