forked from yui/builder
/
jslint-console.js
71 lines (57 loc) · 1.58 KB
/
jslint-console.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
/**
* Javascript Shell Script to Load and JSLint js files through Rhino Javascript Shell
* The jslint source file is expected as the first argument, followed by the list of JS files to JSLint
*
* e.g.
* java -j js.jar /tools/fulljslint.js testFile1.js testFile2.js testFile3.js
**/
var jslintsrc = arguments.splice(0,1);
var scripts = arguments;
load(jslintsrc);
(function(){ // Just to keep stuff seperate from JSLINT code
var OPTS = {
browser : true,
//laxLineEnd : true,
undef: true,
newcap: false,
predef:["YUI"]
};
function test(jsFile) {
print("Running JSLint on : " + jsFile);
var js = readFile(jsFile);
var success = JSLINT(js, OPTS);
if (success) {
print("- OK");
} else {
print(" \n");
for (var i=0; i < JSLINT.errors.length; ++i) {
var e = JSLINT.errors[i];
if (e) {
print("\t" + e.line + ", " + e.character + ": " + e.reason + "\n\t" + clean(e.evidence) + "\n");
}
}
print(" \n");
// Last item is null if JSLint hit a fatal error
if (JSLINT.errors && JSLINT.errors[JSLINT.errors.length-1] === null) {
throw new Error("Fatal JSLint Exception. Stopped lint");
}
}
}
function clean(str) {
var trimmed = "";
if (str) {
if(str.length <= 500) {
trimmed = str.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
} else {
trimmed = "[Code Evidence Omitted: Greater than 500 chars]";
}
}
return trimmed;
}
function jslint(aScripts) {
for (var i = 0; i < aScripts.length; ++i) {
test(aScripts[i]);
}
};
jslint(scripts);
})();