You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
4.5 KiB
108 lines
4.5 KiB
|
|
/* compatibility between NodeJS and Rhino */ |
|
if (typeof print === 'undefined') |
|
print = console.log; |
|
if (typeof console === 'undefined') |
|
console = { log: print }; |
|
if (typeof process !== 'undefined') |
|
arguments = process.argv.splice(2); |
|
if (typeof quit === 'undefined') |
|
quit = process.exit; |
|
if (typeof readFile === 'undefined') { |
|
var fs = require("fs"); |
|
readFile = function (filename) { return fs.readFileSync(filename, "utf-8"); }; |
|
} |
|
|
|
(function (a) { |
|
var options = { |
|
anon : false, // if the space may be omitted in anonymous function declarations |
|
bitwise : false, // if bitwise operators should be allowed |
|
browser : false, // if the standard browser globals should be predefined |
|
cap : false, // if upper case HTML should be allowed |
|
confusion : false, // if types can be used inconsistently |
|
'continue' : false, // if the continuation statement should be tolerated |
|
css : false, // if CSS workarounds should be tolerated |
|
debug : false, // if debugger statements should be allowed |
|
devel : false, // if logging should be allowed (console, alert, etc.) |
|
eqeq : false, // if == should be allowed |
|
es5 : false, // if ES5 syntax should be allowed |
|
evil : false, // if eval should be allowed |
|
forin : false, // if for in statements need not filter |
|
fragment : false, // if HTML fragments should be allowed |
|
indent : 10, // the indentation factor |
|
maxerr : 1000, // the maximum number of errors to allow |
|
maxlen : 256, // the maximum length of a source line |
|
newcap : false, // if constructor names capitalization is ignored |
|
node : false, // if Node.js globals should be predefined |
|
nomen : false, // if names may have dangling _ |
|
on : false, // if HTML event handlers should be allowed |
|
passfail : false, // if the scan should stop on first error |
|
plusplus : false, // if increment/decrement should be allowed |
|
properties : false, // if all property names must be declared with /*properties*/ |
|
regexp : false, // if the . should be allowed in regexp literals |
|
rhino : false, // if the Rhino environment globals should be predefined |
|
undef : false, // if variables can be declared out of order |
|
unparam : false, // if unused parameters should be tolerated |
|
sloppy : false, // if the 'use strict'; pragma is optional |
|
sub : false, // if all forms of subscript notation are tolerated |
|
vars : false, // if multiple var statements per function should be allowed |
|
white : false, // if sloppy whitespace is tolerated |
|
widget : false, // if the Yahoo Widgets globals should be predefined |
|
windows : false // if MS Windows-specific globals should be predefined |
|
}; |
|
|
|
var k; |
|
var m |
|
for (k = 0; k < a.length; k++) { |
|
if ( a[k].substring(0, 1) != '-' |
|
&& a[k].substring(0, 1) != '+') |
|
break; |
|
var name = a[k] |
|
var value = name.substring(0, 1) == "+" ? true : false; |
|
name = name.substring(1) |
|
if ((m = name.match(/^(.+)=(.+)$/))) { |
|
name = m[1] |
|
value = m[2] |
|
} |
|
if (options[name] == undefined) { |
|
print("jslint: ERROR: invalid command line option \"" + a[k] + "\""); |
|
quit(1); |
|
} |
|
options[name] = value |
|
} |
|
|
|
var e, i, input; |
|
if (!a[k]) { |
|
var o = ""; |
|
for (opt in options) { |
|
if (typeof options[opt] == "boolean") |
|
o += " [+|-" + opt + "]" |
|
else |
|
o += " [+" + opt + "=<value>]" |
|
} |
|
print("jslint: USAGE: jslint" + o + " <javascript-file>"); |
|
quit(1); |
|
} |
|
input = readFile(a[k]); |
|
if (!input) { |
|
print("jslint: ERROR: couldn't open file '" + a[k] + "'."); |
|
quit(1); |
|
} |
|
if (!JSLINT(input, options)) { |
|
for (i = 0; i < JSLINT.errors.length; i += 1) { |
|
e = JSLINT.errors[i]; |
|
if (e) { |
|
print('jslint: ERROR: line ' + e.line + ' character ' + |
|
e.character + ': ' + e.reason); |
|
print(e.evidence || ''); |
|
var prefix = ""; |
|
for (var j = 0; j < e.character - 1; j++) |
|
prefix += " "; |
|
print(prefix + '^'); |
|
} |
|
} |
|
quit(2); |
|
} else |
|
quit(); |
|
}(arguments)); |
|
|
|
|