]>
Commit | Line | Data |
---|---|---|
1 | (function (a) { | |
2 | var e, i, j, input, filename, defaults; | |
3 | var error = 0; | |
4 | var errorstring = ''; | |
5 | if (!a[0]) { | |
6 | print("Usage: jslint.js file.js ..."); | |
7 | quit(1); | |
8 | } | |
9 | ||
10 | defaults = { | |
11 | predef: ['Ext', 'PVE', 'PMG', 'PVE_vnc_console_event', 'FormData', 'gettext', 'Proxmox'], | |
12 | devel: true, | |
13 | 'continue': true, /// Allow continue statement | |
14 | bitwise: true, // Allow bitwise operators | |
15 | browser: true, // Assume a browser | |
16 | css: true, // Tolerate CSS workarounds | |
17 | eqeq: true, // Allow `==` && `!=` | |
18 | //immed: true, // Immediate invocations must be wrapped in parens. | |
19 | //nomen: true, // Allow dangling `_` in identifiers | |
20 | newcap: false, // Require initial caps for constructors | |
21 | vars: true, // Allow multiple `var` statements. | |
22 | plusplus: true, // Allow `++` and `--` | |
23 | regexp: true, // Allow `.` and `[^...]` in regex | |
24 | sloppy: true, // Don't require `use strict;` | |
25 | undef: false, // Disallow undeclared variables | |
26 | white: true // Don't apply strict whitespace rules | |
27 | }; | |
28 | ||
29 | for (i = 0; i < a.length; ++i) { | |
30 | filename = a[i]; | |
31 | input = readFile( filename ); | |
32 | if (!input) { | |
33 | print("jslint: Couldn't open file '" + filename + "'."); | |
34 | if (error < 1) { | |
35 | error = 1; | |
36 | } | |
37 | continue; | |
38 | } | |
39 | ||
40 | if (!JSLINT(input, defaults)) { | |
41 | for (j = 0; j < JSLINT.errors.length; j += 1) { | |
42 | e = JSLINT.errors[j]; | |
43 | if (e) { | |
44 | errorstring += ('[' + filename + '] Lint at line ' + e.line + ' character ' + | |
45 | e.character + ': ' + e.reason); | |
46 | errorstring += "\n"; | |
47 | errorstring += ((e.evidence || ''). | |
48 | replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1")); | |
49 | errorstring += "\n\n"; | |
50 | } | |
51 | } | |
52 | if (error < 2) { | |
53 | error = 2; | |
54 | continue; | |
55 | } | |
56 | } else { | |
57 | print("jslint: " + filename + " OK"); | |
58 | } | |
59 | } | |
60 | print(errorstring); | |
61 | quit(error); | |
62 | }(arguments)); |