|
97
|
1 |
/* source comes from a similar jquery script */ |
|
|
2 |
/* run it like this : java -jar rhino.jar jslint-wrapper.js file.js */ |
|
|
3 |
|
|
|
4 |
|
|
|
5 |
if (arguments.length == 1) { |
|
|
6 |
jslint = "jslint.js" |
|
|
7 |
srcfile = arguments[0]; |
|
|
8 |
} else if (arguments.length != 2) { |
|
|
9 |
print("jslint-wrapper jslint.js myfile.js"); |
|
|
10 |
quit(); |
|
|
11 |
} else { |
|
|
12 |
var jslint = arguments[0]; |
|
|
13 |
var srcfile = arguments[1]; |
|
|
14 |
} |
|
|
15 |
|
|
|
16 |
src = readFile(srcfile, "utf8"); |
|
|
17 |
load(jslint); |
|
|
18 |
|
|
|
19 |
JSLINT(src, { browser: true, forin: true, maxerr: 5 }); |
|
|
20 |
|
|
|
21 |
//All of the following are known issues that we think are 'ok' |
|
|
22 |
//(in contradiction with JSLint) more information here: |
|
|
23 |
//http://docs.jquery.com/JQuery_Core_Style_Guidelines |
|
|
24 |
var ok = { |
|
|
25 |
"Expected an identifier and instead saw 'undefined' (a reserved word).": true, |
|
|
26 |
"Use '===' to compare with 'null'.": true, |
|
|
27 |
"Use '!==' to compare with 'null'.": true, |
|
|
28 |
"Expected an assignment or function call and instead saw an expression.": true, |
|
|
29 |
"Expected a 'break' statement before 'case'.": true, |
|
|
30 |
"'e' is already defined.": true, |
|
|
31 |
"Expected exactly one space between 'function' and '('": true |
|
|
32 |
}; |
|
|
33 |
|
|
|
34 |
var e = JSLINT.errors, found = 0, w; |
|
|
35 |
|
|
|
36 |
for ( var i = 0; i < e.length; i++ ) { |
|
|
37 |
w = e[i]; |
|
|
38 |
|
|
|
39 |
if ( !ok[ w.reason ] ) { |
|
|
40 |
found++; |
|
|
41 |
print( "\n" + w.evidence + "\n" ); |
|
|
42 |
print( " Problem at line " + w.line + " character " + w.character + ": " + w.reason ); |
|
|
43 |
} |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
if ( found > 0 ) { |
|
|
47 |
print( "\n" + found + " Error(s) found.\n" ); |
|
|
48 |
|
|
|
49 |
} else { |
|
|
50 |
print( "JSLint check passed.\n" ); |
|
|
51 |
} |