checkstyle.js
2.23 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
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
// Author: Boy Baukema
// http://github.com/relaxnow
module.exports =
{
reporter: function(results, data, opts) {
"use strict";
var files = {},
out = [],
pairs = {
"&": "&",
'"': """,
"'": "'",
"<": "<",
">": ">"
},
fileName, i, issue, errorMessage;
opts = opts || {};
function encode(s) {
for (var r in pairs) {
if (typeof(s) !== "undefined") {
s = s.replace(new RegExp(r, "g"), pairs[r]);
}
}
return s || "";
}
results.forEach(function(result) {
// Register the file
result.file = result.file.replace(/^\.\//, '');
if (!files[result.file]) {
files[result.file] = [];
}
// Create the error message
errorMessage = result.error.reason;
if (opts.verbose) {
errorMessage += ' (' + result.error.code + ')';
}
var typeNo = result.error.code;
var severity = '';
switch (typeNo[0]) {
case 'I':
severity = 'info';
break;
case 'W':
severity = 'warning';
break;
case 'E':
severity = 'error';
break;
}
// Add the error
files[result.file].push({
severity: severity,
line: result.error.line,
column: result.error.character,
message: errorMessage,
source: 'jshint.' + result.error.code
});
});
out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.push("<checkstyle version=\"4.3\">");
for (fileName in files) {
if (files.hasOwnProperty(fileName)) {
out.push("\t<file name=\"" + fileName + "\">");
for (i = 0; i < files[fileName].length; i++) {
issue = files[fileName][i];
out.push(
"\t\t<error " +
"line=\"" + issue.line + "\" " +
"column=\"" + issue.column + "\" " +
"severity=\"" + issue.severity + "\" " +
"message=\"" + encode(issue.message) + "\" " +
"source=\"" + encode(issue.source) + "\" " +
"/>"
);
}
out.push("\t</file>");
}
}
out.push("</checkstyle>");
console.log(out.join("\n"));
}
};