jshint passes - run 'node jshint/run.js'. running jshint with a couple jshint options and workarounds to allow certain jasmine-specific styles. many actual style problems are fixed. the jshint run is integrated into rake jasmine:lint.

This commit is contained in:
Steve Conover
2011-02-26 15:07:59 -08:00
parent 9f90c4eca5
commit f41af6c2d0
20 changed files with 184 additions and 139 deletions

View File

@@ -221,7 +221,7 @@
lightseagreen, lightskyblue, lightslategray, lightsteelblue,
lightyellow, lime, limegreen, line, "line-height", linen, link,
"list-style", "list-style-image", "list-style-position",
"list-style-type", load, loadClass, localStorage, location, log, m, magenta,
"list-style-type", load, loadClass, localStorage, location, log, loopfunc, m, magenta,
map, margin, "margin-bottom", "margin-left", "margin-right", "margin-top",
mark, "marker-offset", maroon, match, "max-height", "max-width", maxerr,
maxlen, md5, mediumaquamarine, mediumblue, mediumorchid, mediumpurple,
@@ -314,9 +314,9 @@ var JSHINT = (function () {
},
// These are the JSHint options.
// These are the JSHint boolean options.
options = {
boolOptions = {
adsafe : true, // if ADsafe should be enforced
asi : true, // if automatic semicolon insertion should be tolerated
bitwise : true, // if bitwise operators should not be allowed
@@ -336,6 +336,7 @@ var JSHINT = (function () {
immed : true, // if immediate invocations must be wrapped in parens
jquery : true, // if jQuery globals should be predefined
laxbreak : true, // if line breaks should not be checked
loopfunc : true, // if functions should be allowed to be defined within loops
newcap : true, // if constructor names must be capitalized
noarg : true, // if arguments.caller and arguments.callee should be disallowed
node : true, // if the Node.js environment globals should be predefined
@@ -356,7 +357,7 @@ var JSHINT = (function () {
white : true, // if strict whitespace rules apply
widget : true // if the Yahoo Widgets globals should be predefined
},
// browser contains a set of global names which are commonly provided by a
// web browser environment.
@@ -2017,7 +2018,7 @@ klass: do {
warning("ADsafe restriction.");
}
obj = option;
filter = options;
filter = boolOptions;
break;
case '/*global':
if (option.safe) {
@@ -4896,7 +4897,7 @@ loop: for (;;) {
t = nexttoken;
adjacent(token, nexttoken);
f = doFunction(i);
if (funct['(loopage)']) {
if (!option.loopfunc && funct['(loopage)']) {
warning("Don't make functions within a loop.", t);
}
p = f['(params)'];
@@ -5032,7 +5033,7 @@ loop: for (;;) {
nonadjacent(token, nexttoken);
}
doFunction(i);
if (funct['(loopage)']) {
if (!option.loopfunc && funct['(loopage)']) {
warning("Don't make functions within a loop.");
}
return this;
@@ -5529,11 +5530,10 @@ loop: for (;;) {
// The actual JSHINT function itself.
var itself = function (s, o, g) {
var itself = function (s, o) {
var a, i, k;
JSHINT.errors = [];
predefined = Object.create(standard);
combine(predefined, g || {});
if (o) {
a = o.predef;
if (a) {
@@ -5552,22 +5552,23 @@ loop: for (;;) {
o.safe = true;
}
if (o.safe) {
o.browser =
o.css =
o.debug =
o.devel =
o.evil =
o.forin =
o.on =
o.rhino =
o.windows =
o.sub =
o.widget = false;
o.browser =
o.css =
o.debug =
o.devel =
o.evil =
o.forin =
o.loopfunc =
o.on =
o.rhino =
o.windows =
o.sub =
o.widget = false;
o.eqeqeq =
o.nomen =
o.safe =
o.undef = true;
o.eqeqeq =
o.nomen =
o.safe =
o.undef = true;
predefined.Date =
predefined['eval'] =

View File

@@ -1,42 +1,70 @@
var fs = require("fs")
var sys = require("sys")
var path = require("path")
var fs = require("fs");
var sys = require("sys");
var path = require("path");
var JSHINT = require("./jshint").JSHINT;
function isVendorFile(fullPath) {
var fileName = path.basename(fullPath)
var vendorFiles = ["json2.js", "jshint.js", "publish.js"]
for (var i=0; i<vendorFiles.length; i++) if (fileName==vendorFiles[i]) return true
return false
function isExcluded(fullPath) {
var fileName = path.basename(fullPath);
var excludeFiles = ["json2.js", "jshint.js", "publish.js", "node_suite.js", "jasmine.js", "jasmine-html.js"];
for (var i=0; i<excludeFiles.length; i++) if (fileName==excludeFiles[i]) return true;
return false;
}
function allJasmineJsFiles(rootDir) {
var files = []
var things = fs.readdirSync(rootDir)
var files = [];
var things = fs.readdirSync(rootDir);
for (var i=0; i<things.length; i++) {
var thing = things[i]
var fullPath = rootDir + "/" + thing
var thing = things[i];
var fullPath = rootDir + "/" + thing;
if (fs.statSync(fullPath).isDirectory()) {
files = files.concat(allJasmineJsFiles(fullPath))
files = files.concat(allJasmineJsFiles(fullPath));
} else {
if (fullPath.match(/\.js$/) && !isVendorFile(fullPath)) files.push(fullPath)
if (fullPath.match(/\.js$/) && !isExcluded(fullPath)) files.push(fullPath);
}
}
return files
return files;
}
var jasmineJsFiles = allJasmineJsFiles(".")
var jasmineJsFiles = allJasmineJsFiles(".");
jasmineJsFiles.reverse(); //cheap way to do the stuff in src stuff first
var jasmineJsHintConfig = {}
var jasmineGlobals = {}
var jasmineJsHintConfig = {
forin:true, //while it's possible that we could be
//considering unwanted prototype methods, mostly
//we're doing this because the jsobjects are being
//used as maps.
loopfunc:true //we're fine with functions defined inside loops (setTimeout functions, etc)
};
var jasmineGlobals = {};
//jasmine.undefined is a jasmine-ism, let's let it go...
function removeJasmineUndefinedErrors(errors) {
var keepErrors = [];
for(var i=0; i<errors.length; i++) {
if (!(errors[i] &&
errors[i].raw &&
errors[i].evidence &&
( errors[i].evidence.match(/jasmine\.undefined/) ||
errors[i].evidence.match(/diz be undefined yo/) )
)) keepErrors.push(errors[i]);
}
return keepErrors;
}
for(var i=0; i<jasmineJsFiles.length; i++) {
var file = jasmineJsFiles[i]
var result = JSHINT(fs.readFileSync(file, "utf8"))
if (!result) {
console.log("JSHINT failure: ", file)
console.log(JSHINT.data().errors)
process.exit(1)
var file = jasmineJsFiles[i];
JSHINT(fs.readFileSync(file, "utf8"), jasmineJsHintConfig);
var errors = JSHINT.data().errors || [];
errors = removeJasmineUndefinedErrors(errors);
if (errors.length>=1) {
console.log("JSHINT failure: ", file);
console.log(errors);
process.exit(1);
}
}