-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
121 lines (107 loc) · 3.54 KB
/
index.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var path = require("path");
var writeLine = function (line) {
if (arguments.length === 0) {
line = "";
}
console.log(line);
};
var hasProp = Object.prototype.hasOwnProperty;
function repeat(len, str) {
var ret = "";
while (ret.length < len) {
ret += str;
}
return ret;
}
function PathFormatter() {
}
PathFormatter.prototype = Object.create({
name: "tslint-msbuild-path",
getName: function () {
return this.name;
},
format: function (failures) {
var output = "";
var files = {};
var data = [];
var codeMaxLen = 0;
failures.forEach(function (failure) {
var fileName = failure.getFileName();
var res;
if (hasProp.call(files, fileName)) {
res = files[fileName];
}
else {
files[fileName] = res = {
file: failure.getFileName(),
errors: []
};
data.push(res);
}
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var item = {
reason: failure.getFailure(),
line: lineAndCharacter.line + 1,
character: lineAndCharacter.character + 1,
code: (failure.getRuleName ? failure.getRuleName() : '')
};
res.errors.push(item);
codeMaxLen = item.code ? Math.max(item.code.length, codeMaxLen) : codeMaxLen;
});
data.forEach(function (res) {
var errors = res.errors;
var file;
if (res.file) {
file = path.resolve(res.file);
}
if (!file) {
file = "<unknown file>";
}
var head = "File \'" + res.file + "\'";
if (!errors || errors.length === 0) {
} else {
errors.sort(function (a, b) {
if (a && !b) {
return -1;
}
else if (!a && b) {
return 1;
}
if (a.line < b.line) {
return -1;
}
else if (a.line > b.line) {
return 1;
}
if (a.character < b.character) {
return -1;
}
else if (a.character > b.character) {
return 1;
}
return 0;
});
errors.forEach(function (error) {
var line = "";
if (!error) {
return;
}
line += file + "(" + error.line + "," + error.character + "): error: ";
if (error.code) {
line += "[" + error.code + "]" + repeat(codeMaxLen + 1 - error.code.length, " ");
}
line += error.reason ? error.reason : "<undefined reason>";
if (typeof error.evidence !== "undefined") {
line += "\n" + error.evidence;
}
writeLine(line);
});
writeLine("");
}
});
return output;
}
});
module.exports = {
Formatter: PathFormatter
};