source: imaps-frontend/node_modules/eslint/lib/cli-engine/formatters/checkstyle.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @fileoverview CheckStyle XML reporter
3 * @author Ian Christian Myers
4 */
5"use strict";
6
7const 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 */
19function 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
31module.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};
Note: See TracBrowser for help on using the repository browser.