Skip to content

Allow multiple filenames to be passed to Rhino CLI #313

Merged
merged 3 commits into from Oct 25, 2011
View
60 env/jshint-rhino.js
@@ -4,13 +4,26 @@
load("jshint.js");
(function (args) {
- var name = args[0],
- optstr = args[1], // arg1=val1,arg2=val2,...
- predef = args[2], // global1=override,global2,global3,...
+ var filenames = [],
+ optstr, // arg1=val1,arg2=val2,...
+ predef, // global1=override,global2,global3,...
opts = { rhino: true },
- input;
+ retval = 0;
- if (!name) {
+ args.forEach(function(arg){
+ if (arg.indexOf("=") > -1){
+ //first time it's the options
+ if (!optstr){
+ optstr = arg;
+ } else if (!predef) {
+ predef = arg;
+ }
+ } else {
+ filenames.push(arg);
+ }
+ });
+
+ if (filenames.length === 0) {
print('Usage: jshint.js file.js');
quit(1);
}
@@ -27,35 +40,38 @@ load("jshint.js");
default:
return ov;
}
- }(o[1]));
+ })(o[1]);
});
}
-
+
if (predef) {
opts.predef = {};
predef.split(',').forEach(function (arg) {
var global = arg.split('=');
opts.predef[global[0]] = (function (override) {
return (override === 'false') ? false : true;
- }(global[1]));
+ })(global[1]);
});
}
- input = readFile(name);
+ filenames.forEach(function(name){
- if (!input) {
- print('jshint: Couldn\'t open file ' + name);
- quit(1);
- }
+ var input = readFile(name);
- if (!JSHINT(input, opts)) {
- for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
- print(err.reason + ' (' + name + ':' + err.line + ':' + err.character + ')');
- print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
- print('');
+ if (!input) {
+ print('jshint: Couldn\'t open file ' + name);
+ quit(1);
}
- quit(1);
- }
- quit(0);
-}(arguments));
+ if (!JSHINT(input, opts)) {
+ for (var i = 0, err; err = JSHINT.errors[i]; i++) {
+ print(err.reason + ' (' + name + ':' + err.line + ':' + err.character + ')');
+ print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
+ print('');
+ }
+ retval = 1;
+ }
+ });
+
+ quit(retval);
+}(arguments));
Something went wrong with that request. Please try again.