Commit | Line | Data |
---|---|---|
758a629f DV |
1 | /*jshint boss: true, rhino: true */ |
2 | /*globals JSHINT*/ | |
3 | ||
4 | (function (args) { | |
5 | var filenames = [], | |
6 | optstr, // arg1=val1,arg2=val2,... | |
7 | predef, // global1=override,global2,global3,... | |
8 | opts = { rhino: true }, | |
9 | retval = 0; | |
10 | ||
11 | args.forEach(function (arg) { | |
12 | if (arg.indexOf("=") > -1) { | |
13 | //first time it's the options | |
14 | if (!optstr) { | |
15 | optstr = arg; | |
16 | } else if (!predef) { | |
17 | predef = arg; | |
18 | } | |
19 | } else { | |
20 | filenames.push(arg); | |
21 | } | |
22 | }); | |
23 | ||
24 | if (filenames.length === 0) { | |
25 | print('Usage: jshint.js file.js'); | |
26 | quit(1); | |
27 | } | |
28 | ||
29 | if (optstr) { | |
30 | optstr.split(',').forEach(function (arg) { | |
31 | var o = arg.split('='); | |
32 | opts[o[0]] = (function (ov) { | |
33 | switch (ov) { | |
34 | case 'true': | |
35 | return true; | |
36 | case 'false': | |
37 | return false; | |
38 | default: | |
39 | return ov; | |
40 | } | |
41 | }(o[1])); | |
42 | }); | |
43 | } | |
44 | ||
45 | if (predef) { | |
46 | opts.predef = {}; | |
47 | predef.split(',').forEach(function (arg) { | |
48 | var global = arg.split('='); | |
49 | opts.predef[global[0]] = (function (override) { | |
50 | return (override === 'false') ? false : true; | |
51 | }(global[1])); | |
52 | }); | |
53 | } | |
54 | ||
55 | filenames.forEach(function (name) { | |
56 | ||
57 | var input = readFile(name); | |
58 | ||
59 | if (!input) { | |
60 | print('jshint: Couldn\'t open file ' + name); | |
61 | quit(1); | |
62 | } | |
63 | ||
64 | if (!JSHINT(input, opts)) { | |
65 | for (var i = 0, err; err = JSHINT.errors[i]; i += 1) { | |
66 | print(err.reason + ' (' + name + ':' + err.line + ':' + err.character + ')'); | |
67 | print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1")); | |
68 | print(''); | |
69 | } | |
70 | retval = 1; | |
71 | } | |
72 | }); | |
73 | ||
74 | quit(retval); | |
75 | }(arguments)); |