1 | /**
|
2 | * @fileoverview unix-style formatter.
|
3 | * @author oshi-shinobu
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Helper Functions
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | /**
|
12 | * Returns a canonical error level string based upon the error message passed in.
|
13 | * @param {Object} message Individual error message provided by eslint
|
14 | * @returns {string} Error level string
|
15 | */
|
16 | function getMessageType(message) {
|
17 | if (message.fatal || message.severity === 2) {
|
18 | return "Error";
|
19 | } else {
|
20 | return "Warning";
|
21 | }
|
22 | }
|
23 |
|
24 |
|
25 | //------------------------------------------------------------------------------
|
26 | // Public Interface
|
27 | //------------------------------------------------------------------------------
|
28 |
|
29 | module.exports = function(results) {
|
30 |
|
31 | let output = "",
|
32 | total = 0;
|
33 |
|
34 | results.forEach(function(result) {
|
35 |
|
36 | const messages = result.messages;
|
37 |
|
38 | total += messages.length;
|
39 |
|
40 | messages.forEach(function(message) {
|
41 |
|
42 | output += result.filePath + ":";
|
43 | output += (message.line || 0) + ":";
|
44 | output += (message.column || 0) + ":";
|
45 | output += " " + message.message + " ";
|
46 | output += "[" + getMessageType(message) +
|
47 | (message.ruleId ? "/" + message.ruleId : "") + "]";
|
48 | output += "\n";
|
49 |
|
50 | });
|
51 |
|
52 | });
|
53 |
|
54 | if (total > 0) {
|
55 | output += "\n" + total + " problem" + (total !== 1 ? "s" : "");
|
56 | }
|
57 |
|
58 | return output;
|
59 | };
|