1 | /**
|
---|
2 | * @fileoverview CheckStyle XML reporter
|
---|
3 | * @author Ian Christian Myers
|
---|
4 | */
|
---|
5 | "use strict";
|
---|
6 |
|
---|
7 | const xmlEscape = require("../xml-escape");
|
---|
8 |
|
---|
9 | //------------------------------------------------------------------------------
|
---|
10 | // Helper Functions
|
---|
11 | //------------------------------------------------------------------------------
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Returns the severity of warning or error
|
---|
15 | * @param {Object} message message object to examine
|
---|
16 | * @returns {string} severity level
|
---|
17 | * @private
|
---|
18 | */
|
---|
19 | function getMessageType(message) {
|
---|
20 | if (message.fatal || message.severity === 2) {
|
---|
21 | return "error";
|
---|
22 | }
|
---|
23 | return "warning";
|
---|
24 |
|
---|
25 | }
|
---|
26 |
|
---|
27 | //------------------------------------------------------------------------------
|
---|
28 | // Public Interface
|
---|
29 | //------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | module.exports = function(results) {
|
---|
32 |
|
---|
33 | let output = "";
|
---|
34 |
|
---|
35 | output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
---|
36 | output += "<checkstyle version=\"4.3\">";
|
---|
37 |
|
---|
38 | results.forEach(result => {
|
---|
39 | const messages = result.messages;
|
---|
40 |
|
---|
41 | output += `<file name="${xmlEscape(result.filePath)}">`;
|
---|
42 |
|
---|
43 | messages.forEach(message => {
|
---|
44 | output += [
|
---|
45 | `<error line="${xmlEscape(message.line || 0)}"`,
|
---|
46 | `column="${xmlEscape(message.column || 0)}"`,
|
---|
47 | `severity="${xmlEscape(getMessageType(message))}"`,
|
---|
48 | `message="${xmlEscape(message.message)}${message.ruleId ? ` (${message.ruleId})` : ""}"`,
|
---|
49 | `source="${message.ruleId ? xmlEscape(`eslint.rules.${message.ruleId}`) : ""}" />`
|
---|
50 | ].join(" ");
|
---|
51 | });
|
---|
52 |
|
---|
53 | output += "</file>";
|
---|
54 |
|
---|
55 | });
|
---|
56 |
|
---|
57 | output += "</checkstyle>";
|
---|
58 |
|
---|
59 | return output;
|
---|
60 | };
|
---|