2 * @fileoverview Stylish reporter
3 * @author Sindre Sorhus
7 var chalk = require("chalk"),
8 table = require("text-table");
10 //------------------------------------------------------------------------------
12 //------------------------------------------------------------------------------
15 * Given a word and a count, append an s if count is not one.
16 * @param {string} word A word in its singular form.
17 * @param {int} count A number controlling whether word should be pluralized.
18 * @returns {string} The original word with an s on the end if count is not one.
20 function pluralize(word, count) {
21 return (count === 1 ? word : word + "s");
24 //------------------------------------------------------------------------------
26 //------------------------------------------------------------------------------
28 module.exports = function(results) {
34 summaryColor = "yellow";
36 results.forEach(function(result) {
37 var messages = result.messages;
39 if (messages.length === 0) {
43 total += messages.length;
44 output += chalk.underline(result.filePath) + "\n";
47 messages.map(function(message) {
50 if (message.fatal || message.severity === 2) {
51 messageType = chalk.red("error");
55 messageType = chalk.yellow("warning");
64 message.message.replace(/\.$/, ""),
65 chalk.gray(message.ruleId || "")
69 align: ["", "r", "l"],
70 stringLength: function(str) {
71 return chalk.stripColor(str).length;
74 ).split("\n").map(function(el) {
75 return el.replace(/(\d+)\s+(\d+)/, function(m, p1, p2) {
76 return chalk.gray(p1 + ":" + p2);
78 }).join("\n") + "\n\n";
82 output += chalk[summaryColor].bold([
83 "\u2716 ", total, pluralize(" problem", total),
84 " (", errors, pluralize(" error", errors), ", ",
85 warnings, pluralize(" warning", warnings), ")\n"
89 return total > 0 ? output : "";