Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #152 regarding compact output format #192

Merged
merged 1 commit into from
Oct 18, 2011
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
13 changes: 11 additions & 2 deletions src/formatters/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
});
Expand Down
22 changes: 11 additions & 11 deletions tests/formatters/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down