-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporter.js
65 lines (46 loc) · 1.17 KB
/
reporter.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
"use strict";
module.exports = {
reporter: function (data) {
var thereAreErrors = false,
errors = {},
output = "";
data.forEach(function (r) {
var fileName = r.file;
if (typeof errors[fileName] === 'undefined') {
thereAreErrors = true;
errors[fileName] = 1;
} else {
errors[fileName] += 1;
}
});
if (thereAreErrors) {
var file,
fileLength,
bespokePaddingLength,
bespokePaddingText,
paddingChar = ".",
padding = 10,
longestFileNameLength = 0,
totalFileErrors;
for (file in errors) {
fileLength = file.length;
if (longestFileNameLength < fileLength) {
longestFileNameLength = fileLength;
}
}
padding += longestFileNameLength;
for (file in errors) {
fileLength = file.length;
bespokePaddingLength = padding - fileLength;
bespokePaddingText = " ";
for (var i = 0; i < bespokePaddingLength; i++) {
bespokePaddingText += paddingChar;
}
bespokePaddingText += " ";
totalFileErrors = errors[file];
output += file + bespokePaddingText + totalFileErrors + " error" + ((totalFileErrors == 1) ? "" : "s") + "\n";
}
process.stdout.write(output);
}
}
};