-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun_hint.sh
executable file
·61 lines (51 loc) · 1.45 KB
/
run_hint.sh
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
#!/usr/bin/env node
var JSHINT = require('jshint').JSHINT;
var fs = require('fs');
var path = require('path');
var asyncblock = require('asyncblock');
var codeDir = path.join(__dirname, 'lib');
var showErrors = function(filePath, result){
var len = result.errors.length;
for (var i = 0; i < len; i++) {
var pad = '' + (i + 1);
while (pad.length < 3) {
pad = ' ' + pad;
}
var e = result.errors[i];
if (e) {
console.error('at (' + filePath + ":" + e.line + ":" + e.character + ')');
console.error(' ' + e.reason);
console.error( ' ' + (e.evidence || '').replace(/^\s+|\s+$/, ""));
console.error('');
}
}
};
fs.readdir(codeDir, function(err, list){
if(err) {
throw err;
}
var options = {
node: true,
devel: true,
eqnull: true,
es5: true,
curly: true,
newcap: true,
undef: true,
onecase: true,
scripturl: true,
latedef: false,
loopfunc: true,
proto: true
};
asyncblock(function(flow){
list.forEach(function(file){
var fullPath = path.join(codeDir, file);
var fileContents = flow.sync( fs.readFile(fullPath, 'utf8', flow.callback()) );
var result = JSHINT(fileContents, options);
if(!result){
showErrors(fullPath, JSHINT.data());
}
});
});
});