Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix how Rhino wrapper treats predefined args.

This patch fixes how Rhino wrapper treats predefined args. You don't
need to include '=' anymore and default override value is now false.

Here's wrapper's new signature:

jshint-rhino.js [filename,..] [option=true,..] [global=true,global,..]

Rules:

 * options must follow filenames
 * options must have '=' in them
 * predefs must follow options

Closes GH-569.
  • Loading branch information...
commit 6fbc8f58d1451b99e610830c0d08f17428b33553 1 parent 14e97cb
@valueof valueof authored
Showing with 31 additions and 26 deletions.
  1. +31 −26 env/rhino.js
View
57 env/rhino.js
@@ -1,42 +1,49 @@
-/*jshint boss: true, rhino: true, unused: true, undef: true */
+/*jshint boss: true, rhino: true, unused: true, undef: true, white: true, quotmark: double */
/*global JSHINT*/
(function (args) {
- var filenames = [],
- optstr, // arg1=val1,arg2=val2,...
- predef, // global1=override,global2,global3,...
- opts = {},
- retval = 0;
+ var filenames = [];
+ var optstr; // arg1=val1,arg2=val2,...
+ var predef; // global1=true,global2,global3,...
+ var opts = {};
+ var retval = 0;
args.forEach(function (arg) {
if (arg.indexOf("=") > -1) {
- //first time it's the options
if (!optstr) {
+ // First time it's the options.
optstr = arg;
- } else if (!predef) {
+ } else {
predef = arg;
}
- } else {
- filenames.push(arg);
+
+ return;
+ }
+
+ if (optstr) {
+ predef = arg;
+ return;
}
+
+ filenames.push(arg);
});
if (filenames.length === 0) {
- print('Usage: jshint.js file.js');
+ print("Usage: jshint.js file.js");
quit(1);
}
if (optstr) {
- optstr.split(',').forEach(function (arg) {
- var o = arg.split('=');
- if (o[0] === 'indent') {
+ optstr.split(",").forEach(function (arg) {
+ var o = arg.split("=");
+ if (o[0] === "indent") {
opts[o[0]] = parseInt(o[1], 10);
} else {
opts[o[0]] = (function (ov) {
switch (ov) {
- case 'true':
+ case "true":
return true;
- case 'false':
+ case "false":
return false;
default:
return ov;
@@ -48,28 +55,26 @@
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]));
+
+ predef.split(",").forEach(function (arg) {
+ var global = arg.split("=");
+ opts.predef[global[0]] = global[1] === "true" ? true : false;
});
}
filenames.forEach(function (name) {
-
var input = readFile(name);
if (!input) {
- print('jshint: Couldn\'t open file ' + name);
+ print("jshint: Couldn't open file " + name);
quit(1);
}
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('');
+ print(err.reason + " (" + name + ":" + err.line + ":" + err.character + ")");
+ print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
+ print("");
}
retval = 1;
}
Please sign in to comment.
Something went wrong with that request. Please try again.