checkstyleFormatter.js
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var abstractFormatter_1 = require("../language/formatter/abstractFormatter");
var Formatter = (function (_super) {
__extends(Formatter, _super);
function Formatter() {
_super.apply(this, arguments);
}
Formatter.prototype.format = function (failures) {
var output = '<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3">';
if (failures.length) {
output += "<file name=\"" + this.escapeXml(failures[0].getFileName()) + "\">";
for (var _i = 0, failures_1 = failures; _i < failures_1.length; _i++) {
var failure = failures_1[_i];
output += "<error line=\"" + (failure.getStartPosition().getLineAndCharacter().line + 1) + "\" ";
output += "column=\"" + (failure.getStartPosition().getLineAndCharacter().character + 1) + "\" ";
output += "severity=\"warning\" ";
output += "message=\"" + this.escapeXml(failure.getFailure()) + "\" ";
output += "source=\"failure.tslint." + this.escapeXml(failure.getRuleName()) + "\" />";
}
output += "</file>";
}
output += "</checkstyle>";
return output;
};
Formatter.prototype.escapeXml = function (str) {
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/'/g, "'")
.replace(/"/g, """);
};
return Formatter;
}(abstractFormatter_1.AbstractFormatter));
exports.Formatter = Formatter;