1 | /**
|
2 | * @fileoverview Compact reporter
|
3 | * @author Nicholas C. Zakas
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Helper Functions
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | /**
|
12 | * Returns the severity of warning or error
|
13 | * @param {Object} message message object to examine
|
14 | * @returns {string} severity level
|
15 | * @private
|
16 | */
|
17 | function getMessageType(message) {
|
18 | if (message.fatal || message.severity === 2) {
|
19 | return "Error";
|
20 | }
|
21 | return "Warning";
|
22 |
|
23 | }
|
24 |
|
25 |
|
26 | //------------------------------------------------------------------------------
|
27 | // Public Interface
|
28 | //------------------------------------------------------------------------------
|
29 |
|
30 | module.exports = function(results) {
|
31 |
|
32 | let output = "",
|
33 | total = 0;
|
34 |
|
35 | results.forEach(result => {
|
36 |
|
37 | const messages = result.messages;
|
38 |
|
39 | total += messages.length;
|
40 |
|
41 | messages.forEach(message => {
|
42 |
|
43 | output += `${result.filePath}: `;
|
44 | output += `line ${message.line || 0}`;
|
45 | output += `, col ${message.column || 0}`;
|
46 | output += `, ${getMessageType(message)}`;
|
47 | output += ` - ${message.message}`;
|
48 | output += message.ruleId ? ` (${message.ruleId})` : "";
|
49 | output += "\n";
|
50 |
|
51 | });
|
52 |
|
53 | });
|
54 |
|
55 | if (total > 0) {
|
56 | output += `\n${total} problem${total !== 1 ? "s" : ""}`;
|
57 | }
|
58 |
|
59 | return output;
|
60 | };
|