4 * Copyright 2013 Palantir Technologies, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
27 /* tslint:enable:object-literal-sort-keys */
28 Formatter.prototype.format = function (failures) {
29 var output = '<pmd version="tslint">';
30 for (var _i = 0, failures_1 = failures; _i < failures_1.length; _i++) {
31 var failure = failures_1[_i];
32 var failureString = failure
34 .replace(/&/g, "&")
35 .replace(/</g, "<")
36 .replace(/>/g, ">")
37 .replace(/'/g, "'")
38 .replace(/"/g, """);
39 var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
40 var priority = failure.getRuleSeverity() === "warning" ? 4 : 3;
41 output += "<file name=\"" + failure.getFileName();
42 output += "\"><violation begincolumn=\"" + (lineAndCharacter.character + 1);
43 output += "\" beginline=\"" + (lineAndCharacter.line + 1);
44 output += "\" priority=\"" + priority + "\"";
45 output += " rule=\"" + failureString + "\"></violation></file>";
50 /* tslint:disable:object-literal-sort-keys */
51 Formatter.metadata = {
53 description: "Formats errors as though they were PMD output.",
54 descriptionDetails: "Imitates the XML output from PMD. All errors have a priority of 1.",
55 sample: Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n <pmd version=\"tslint\">\n <file name=\"myFile.ts\">\n <violation begincolumn=\"14\" beginline=\"1\" priority=\"3\" rule=\"Missing semicolon\"></violation>\n </file>\n </pmd>"], ["\n <pmd version=\"tslint\">\n <file name=\"myFile.ts\">\n <violation begincolumn=\"14\" beginline=\"1\" priority=\"3\" rule=\"Missing semicolon\"></violation>\n </file>\n </pmd>"]))),
59 }(abstractFormatter_1.AbstractFormatter));
60 exports.Formatter = Formatter;