.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / formatters / junitFormatter.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2018 Palantir Technologies, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var abstractFormatter_1 = require("../language/formatter/abstractFormatter");
21 var Utils = require("../utils");
22 var Formatter = /** @class */ (function (_super) {
23     tslib_1.__extends(Formatter, _super);
24     function Formatter() {
25         return _super !== null && _super.apply(this, arguments) || this;
26     }
27     /* tslint:enable:object-literal-sort-keys */
28     Formatter.prototype.format = function (failures, _fixes, fileNames) {
29         var output = '<?xml version="1.0" encoding="utf-8"?><testsuites package="tslint">';
30         var failureFileNames = new Set(failures.map(function (f) { return f.getFileName(); }).slice());
31         if (failures.length !== 0) {
32             var failuresSorted = failures.sort(function (a, b) {
33                 return a.getFileName().localeCompare(b.getFileName());
34             });
35             var previousFilename = null;
36             for (var _i = 0, failuresSorted_1 = failuresSorted; _i < failuresSorted_1.length; _i++) {
37                 var failure = failuresSorted_1[_i];
38                 var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
39                 var message = this.escapeXml(failure.getFailure());
40                 var rule = this.escapeXml(failure.getRuleName());
41                 var severity = failure.getRuleSeverity();
42                 if (failure.getFileName() !== previousFilename) {
43                     if (previousFilename !== null) {
44                         output += "</testsuite>";
45                     }
46                     previousFilename = failure.getFileName();
47                     output += "<testsuite name=\"" + this.escapeXml(failure.getFileName()) + "\">";
48                 }
49                 output += "<testcase name=\"" + rule + "\" ";
50                 output += "classname=\"" + this.escapeXml(failure.getFileName()) + "\">";
51                 output += "<failure type=\"" + severity + "\">" + message + " ";
52                 output += "Line " + (lineAndCharacter.line + 1) + ", ";
53                 output += "Column " + (lineAndCharacter.character + 1);
54                 output += "</failure>";
55                 output += "</testcase>";
56             }
57             if (previousFilename !== null) {
58                 output += "</testsuite>";
59             }
60         }
61         if (fileNames !== undefined && fileNames.length !== 0) {
62             // Filter out files which have had a failure associated with them.
63             var filteredFileNames = fileNames.filter(function (fileName) { return !failureFileNames.has(fileName); });
64             for (var _a = 0, filteredFileNames_1 = filteredFileNames; _a < filteredFileNames_1.length; _a++) {
65                 var fileName = filteredFileNames_1[_a];
66                 output += "<testsuite name=\"" + this.escapeXml(fileName) + "\" errors=\"0\">";
67                 output += "<testcase name=\"" + this.escapeXml(fileName) + "\" />";
68                 output += "</testsuite>";
69             }
70         }
71         output += "</testsuites>";
72         return output;
73     };
74     Formatter.prototype.escapeXml = function (str) {
75         return str
76             .replace(/&/g, "&amp;")
77             .replace(/</g, "&lt;")
78             .replace(/>/g, "&gt;")
79             .replace(/'/g, "&#39;")
80             .replace(/"/g, "&quot;");
81     };
82     /* tslint:disable:object-literal-sort-keys */
83     Formatter.metadata = {
84         formatterName: "junit",
85         description: "Formats errors as though they were JUnit output.",
86         descriptionDetails: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Imitates the JUnit XML Output"], ["\n            Imitates the JUnit XML Output"]))),
87         sample: Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n        <?xml version=\"1.0\" encoding=\"utf-8\"?>\n        <testsuites package=\"tslint\">\n          <testsuite name=\"myFile.ts\">\n            <testcase name=\"semicolon\" classname=\"myFile.ts\">\n              <failure type=\"warning\">Missing semicolon Line 1, Column 14</failure>\n            </testcase>\n          </testsuite>\n        </testsuites>\n        "], ["\n        <?xml version=\"1.0\" encoding=\"utf-8\"?>\n        <testsuites package=\"tslint\">\n          <testsuite name=\"myFile.ts\">\n            <testcase name=\"semicolon\" classname=\"myFile.ts\">\n              <failure type=\"warning\">Missing semicolon Line 1, Column 14</failure>\n            </testcase>\n          </testsuite>\n        </testsuites>\n        "]))),
88         consumer: "machine",
89     };
90     return Formatter;
91 }(abstractFormatter_1.AbstractFormatter));
92 exports.Formatter = Formatter;
93 var templateObject_1, templateObject_2;