forked from eslint/eslint
/
checkstyle.js
129 lines (106 loc) · 4.59 KB
/
checkstyle.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
122
123
124
125
126
127
128
129
/**
* @fileoverview Tests for checkstyle reporter.
* @author Nicholas C. Zakas
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var vows = require("vows"),
assert = require("assert"),
formatter = require("../../../lib/formatters/checkstyle");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
vows.describe("formatter:checkstyle").addBatch({
"when passed a single message": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}],
"should return a string in the format filename: line x, col y, Error - z for errors": function(topic) {
var config = {
rules: { foo: 2 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"error\" message=\"Unexpected foo.\" /></file></checkstyle>", result);
},
"should return a string in the format filename: line x, col y, Warning - z for warnings": function(topic) {
var config = {
rules: { foo: 1 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"warning\" message=\"Unexpected foo.\" /></file></checkstyle>", result);
}
},
"when passed a fatal error message": {
topic: [{
filePath: "foo.js",
messages: [{
fatal: true,
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}],
"should return a string in the format filename: line x, col y, Error - z": function(topic) {
var config = {}; // doesn't matter what's in the config for this test
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"error\" message=\"Unexpected foo.\" /></file></checkstyle>", result);
}
},
"when passed multiple messages": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}, {
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar"
}]
}],
"should return a string with multiple entries": function(topic) {
var config = {
rules: { foo: 2, bar: 1 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"error\" message=\"Unexpected foo.\" /><error line=\"6\" column=\"11\" severity=\"warning\" message=\"Unexpected bar.\" /></file></checkstyle>", result);
}
},
"when passed multiple files with 1 message each": {
topic: [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
line: 5,
column: 10,
ruleId: "foo"
}]
}, {
filePath: "bar.js",
messages: [{
message: "Unexpected bar.",
line: 6,
column: 11,
ruleId: "bar"
}]
}],
"should return a string with multiple entries": function(topic) {
var config = {
rules: { foo: 2, bar: 1 }
};
var result = formatter(topic, config);
assert.equal("<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"error\" message=\"Unexpected foo.\" /></file><file name=\"bar.js\"><error line=\"6\" column=\"11\" severity=\"warning\" message=\"Unexpected bar.\" /></file></checkstyle>", result);
}
}
}).export(module);