.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / formatters / checkstyleFormatter.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 _this = this;
30         var groupedFailures = {};
31         for (var _i = 0, failures_1 = failures; _i < failures_1.length; _i++) {
32             var failure = failures_1[_i];
33             var fileName = failure.getFileName();
34             if (groupedFailures[fileName] !== undefined) {
35                 groupedFailures[fileName].push(failure);
36             }
37             else {
38                 groupedFailures[fileName] = [failure];
39             }
40         }
41         if (fileNames === undefined) {
42             fileNames = Object.keys(groupedFailures);
43         }
44         var formattedFiles = fileNames.map(function (fileName) {
45             var formattedFailures = groupedFailures[fileName] !== undefined
46                 ? groupedFailures[fileName].map(function (f) { return _this.formatFailure(f); })
47                 : [];
48             var joinedFailures = formattedFailures.join(""); // may be empty
49             return "<file name=\"" + _this.escapeXml(fileName) + "\">" + joinedFailures + "</file>";
50         });
51         var joinedFiles = formattedFiles.join("");
52         return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\">" + joinedFiles + "</checkstyle>";
53     };
54     Formatter.prototype.formatFailure = function (failure) {
55         var line = failure.getStartPosition().getLineAndCharacter().line + 1;
56         var column = failure.getStartPosition().getLineAndCharacter().character + 1;
57         var severity = failure.getRuleSeverity();
58         var message = this.escapeXml(failure.getFailure());
59         // checkstyle parser wants "source" to have structure like <anything>dot<category>dot<type>
60         var source = "failure.tslint." + this.escapeXml(failure.getRuleName());
61         return "<error line=\"" + line + "\" column=\"" + column + "\" severity=\"" + severity + "\" message=\"" + message + "\" source=\"" + source + "\" />";
62     };
63     Formatter.prototype.escapeXml = function (str) {
64         return str
65             .replace(/&/g, "&amp;")
66             .replace(/</g, "&lt;")
67             .replace(/>/g, "&gt;")
68             .replace(/'/g, "&#39;")
69             .replace(/"/g, "&quot;");
70     };
71     /* tslint:disable:object-literal-sort-keys */
72     Formatter.metadata = {
73         formatterName: "checkstyle",
74         description: "Formats errors as though they were Checkstyle output.",
75         descriptionDetails: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n            Imitates the XMLLogger from Checkstyle 4.3. All failures have the 'warning' severity. Files without errors are still included."], ["\n            Imitates the XMLLogger from Checkstyle 4.3. All failures have the 'warning' severity. Files without errors are still included."]))),
76         sample: Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n        <?xml version=\"1.0\" encoding=\"utf-8\"?>\n        <checkstyle version=\"4.3\">\n            <file name=\"myFile.ts\">\n                <error line=\"1\" column=\"14\" severity=\"warning\" message=\"Missing semicolon\" source=\"failure.tslint.semicolon\" />\n            </file>\n        </checkstyle>"], ["\n        <?xml version=\"1.0\" encoding=\"utf-8\"?>\n        <checkstyle version=\"4.3\">\n            <file name=\"myFile.ts\">\n                <error line=\"1\" column=\"14\" severity=\"warning\" message=\"Missing semicolon\" source=\"failure.tslint.semicolon\" />\n            </file>\n        </checkstyle>"]))),
77         consumer: "machine",
78     };
79     return Formatter;
80 }(abstractFormatter_1.AbstractFormatter));
81 exports.Formatter = Formatter;
82 var templateObject_1, templateObject_2;