1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | var chalk = require("chalk"),
|
8 | table = require("text-table");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function getMessageType(message, rules) {
|
15 | if (message.fatal) {
|
16 | return chalk.red("error");
|
17 | }
|
18 |
|
19 | var severity = rules[message.ruleId][0] || rules[message.ruleId];
|
20 |
|
21 | if (severity === 2) {
|
22 | return chalk.red("error");
|
23 | }
|
24 |
|
25 | return chalk.yellow("warning");
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | module.exports = function(results, config) {
|
33 |
|
34 | var output = "\n",
|
35 | total = 0,
|
36 | rules = config.rules || {};
|
37 |
|
38 | results.forEach(function(result) {
|
39 | var messages = result.messages;
|
40 |
|
41 | if (messages.length === 0) {
|
42 | return;
|
43 | }
|
44 |
|
45 | total += messages.length;
|
46 | output += chalk.underline(result.filePath) + "\n";
|
47 |
|
48 | output += table(
|
49 | messages.map(function(message) {
|
50 | return [
|
51 | "",
|
52 | message.line || 0,
|
53 | message.column || 0,
|
54 | getMessageType(message, rules),
|
55 | message.message.replace(/\.$/, ""),
|
56 | chalk.gray(message.ruleId)
|
57 | ];
|
58 | }),
|
59 | {
|
60 | align: ["", "r", "l"],
|
61 | stringLength: function(str) {
|
62 | return chalk.stripColor(str).length;
|
63 | }
|
64 | }
|
65 | ).split("\n").map(function(el) {
|
66 | return el.replace(/(\d+)\s+(\d+)/, function(m, p1, p2) {
|
67 | return chalk.gray(p1 + ":" + p2);
|
68 | });
|
69 | }).join("\n") + "\n\n";
|
70 | });
|
71 |
|
72 | output += chalk.red.bold("\u2716 " + total + " problem" + (total === 1 ? "" : "s") + "\n");
|
73 |
|
74 | return total > 0 ? output : "";
|
75 | };
|