]> git.proxmox.com Git - pve-jslint.git/blame - rhino.js
do not exit on first error
[pve-jslint.git] / rhino.js
CommitLineData
46f93004 1(function (a) {
452aa07e
DC
2 var e, i, j, input, filename, defaults;
3 var error = 0;
4 var errorstring = '';
46f93004
DM
5 if (!a[0]) {
6 print("Usage: jslint.js file.js ...");
7 quit(1);
8 }
9
10 defaults = {
7877ef9f 11 predef: ['Ext', 'PVE', 'PMG', 'PVE_vnc_console_event', 'FormData', 'gettext', 'Proxmox'],
46f93004
DM
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 + "'.");
452aa07e
DC
34 if (error < 1) {
35 error = 1;
36 }
37 continue;
46f93004
DM
38 }
39
40 if (!JSLINT(input, defaults)) {
452aa07e
DC
41 for (j = 0; j < JSLINT.errors.length; j += 1) {
42 e = JSLINT.errors[j];
46f93004 43 if (e) {
452aa07e 44 errorstring += ('[' + filename + '] Lint at line ' + e.line + ' character ' +
46f93004 45 e.character + ': ' + e.reason);
452aa07e
DC
46 errorstring += "\n";
47 errorstring += ((e.evidence || '').
46f93004 48 replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
452aa07e 49 errorstring += "\n\n";
46f93004
DM
50 }
51 }
452aa07e
DC
52 if (error < 2) {
53 error = 2;
54 continue;
55 }
46f93004
DM
56 } else {
57 print("jslint: " + filename + " OK");
58 }
59 }
452aa07e
DC
60 print(errorstring);
61 quit(error);
46f93004 62}(arguments));