From 98e27274bd0a5f5754262dc091ae03d463e73791 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 18 Mar 2014 12:46:37 -0700 Subject: [PATCH] Text formatter: fix grammatical error with one problem The summary was incorrectly pluralized and had the wrong verb form when there was only one problem detected. --- src/formatters/text.js | 11 +++++++++-- tests/formatters/text.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/formatters/text.js b/src/formatters/text.js index 3348a4d8..42388b2a 100644 --- a/src/formatters/text.js +++ b/src/formatters/text.js @@ -36,7 +36,14 @@ CSSLint.addFormatter({ return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + "."; } - output = "\n\ncsslint: There are " + messages.length + " problems in " + filename + "."; + output = "\n\ncsslint: There "; + if (messages.length == 1) { + output += "is 1 problem"; + } else { + output += "are " + messages.length + " problems"; + } + output += " in " + filename + "."; + var pos = filename.lastIndexOf("/"), shortFilename = filename; @@ -61,4 +68,4 @@ CSSLint.addFormatter({ return output; } -}); \ No newline at end of file +}); diff --git a/tests/formatters/text.js b/tests/formatters/text.js index 7097a03c..363f892c 100644 --- a/tests/formatters/text.js +++ b/tests/formatters/text.js @@ -13,6 +13,16 @@ Assert.areEqual("\n\ncsslint: No errors in path/to/FILE.", actual); }, + "File with one problem should use proper grammar": function() { + var result = { messages: [ + { type: 'warning', line: 1, col: 1, message: 'BOGUS', evidence: 'ALSO BOGUS', rule: [] } + ], stats: [] }, + error1 = "\n1: warning at line 1, col 1\nBOGUS\nALSO BOGUS", + expected = "\n\ncsslint: There is 1 problem in path/to/FILE.\n\nFILE" + error1, + actual = CSSLint.getFormatter("text").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE"}); + Assert.areEqual(expected, actual); + }, + "Should have no output when quiet option is specified and no errors": function() { var result = { messages: [], stats: [] }, actual = CSSLint.getFormatter("text").formatResults(result, "path/to/FILE", {fullPath: "/absolute/path/to/FILE", quiet: "true"});