forked from uipoet/sublime-jshint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporter.js
83 lines (64 loc) · 2.07 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
module.exports = {
reporter: function (errors, results, done) {
var
errorString = 'Error',
warningString = 'Warning',
file = results[0].file,
errorLength, warningLength, globals, orphans;
function numberWang(wangaNumb) {
var
thatsNumberWang = 8 - wangaNumb,
stayNumberWang = '', i;
for (i = 0; i < thatsNumberWang; i += 1) {
stayNumberWang += ' ';
}
return stayNumberWang;
}
var buffer = '';
console.log = function(){
var args = Array.prototype.slice.call(arguments);
buffer += args.join('');
buffer += '\n';
}
console.log('[JSHint file:', file + ']');
results.forEach(function (result) {
globals = result.implieds;
orphans = result.unused;
warningLength = (globals ? globals.length : 0) + (orphans ? orphans.length : 0);
if (warningLength > 1) {
warningString += 's';
}
});
if (errors) {
errorLength = errors.length;
if (errorLength > 0) {
if (errorLength > 1) {
errorString += 's';
}
console.log(' ', errorLength, errorString + ':');
errors.forEach(function (result) {
var error = result.error;
console.log(numberWang((error.line.toString() + error.character.toString()).length), error.line + ',' + error.character + ':', error.reason);
});
}
}
if (warningLength > 0) {
console.log(' ', warningLength, warningString + ':');
if (globals) {
globals.forEach(function (global) {
for (var line in global.line){
console.log(numberWang(global.line[line].toString().length + 1), global.line[line] + ',1: \'' + global.name + '\' is an implied global variable.');
}
});
}
if (orphans) {
orphans.forEach(function (orphan) {
console.log(numberWang(orphan.line.toString().length + 1), orphan.line + ',1: \'' + orphan.name + '\' is an unused variable.');
});
}
}
process.stdout.write(buffer);
setTimeout('',3000);
}
};