2013-06-21 14:06:20 -04:00
|
|
|
module("JSHint");
|
|
|
|
|
|
|
|
var qHint = function(name, sourceFile, options, globals) {
|
|
|
|
if (sourceFile === undefined || typeof(sourceFile) == "object") {
|
|
|
|
// jsHintTest('file.js', [options])
|
|
|
|
globals = options;
|
|
|
|
options = sourceFile;
|
|
|
|
sourceFile = name;
|
|
|
|
}
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
return asyncTestDiscourse(name, function() {
|
2014-07-22 14:13:13 -04:00
|
|
|
if (typeof window.__jshintSrc !== "undefined") {
|
|
|
|
var src = window.__jshintSrc[sourceFile];
|
|
|
|
if (src) {
|
|
|
|
start();
|
|
|
|
qHint.validateFile(src, options, globals);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.warn("Using AJAX for JSHint " + sourceFile);
|
|
|
|
|
2013-06-21 14:06:20 -04:00
|
|
|
qHint.sendRequest(sourceFile, function(req) {
|
|
|
|
start();
|
|
|
|
|
|
|
|
if (req.status == 200) {
|
|
|
|
|
|
|
|
var text = req.responseText;
|
|
|
|
qHint.validateFile(text, options, globals);
|
|
|
|
} else {
|
|
|
|
ok(false, "HTTP error " + req.status +
|
|
|
|
" while fetching " + sourceFile);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
qHint.validateFile = function (source, options, globals) {
|
|
|
|
var i, len, err;
|
|
|
|
|
2014-07-22 14:13:13 -04:00
|
|
|
source = source.replace(/^[^]*\/\/ IIFE Wrapped Content Begins:\n\n/m, "");
|
|
|
|
source = source.replace(/\n\n\/\/ IIFE Wrapped Content Ends[^]*$/m, "");
|
|
|
|
|
2013-06-21 14:06:20 -04:00
|
|
|
if (JSHINT(source, options, globals)) {
|
|
|
|
ok(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, len = JSHINT.errors.length; i < len; i++) {
|
|
|
|
err = JSHINT.errors[i];
|
|
|
|
if (!err) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(false, err.reason +
|
|
|
|
" on line " + err.line +
|
|
|
|
", character " + err.character);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var XMLHttpFactories = [
|
|
|
|
function () { return new XMLHttpRequest(); },
|
|
|
|
function () { return new ActiveXObject("Msxml2.XMLHTTP"); },
|
|
|
|
function () { return new ActiveXObject("Msxml3.XMLHTTP"); },
|
|
|
|
function () { return new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
|
|
];
|
|
|
|
|
|
|
|
function createXMLHTTPObject() {
|
|
|
|
for (var i = 0; i < XMLHttpFactories.length; i++) {
|
|
|
|
try {
|
|
|
|
return XMLHttpFactories[i]();
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// modified version of XHR script by PPK
|
|
|
|
// http://www.quirksmode.org/js/xmlhttp.html
|
|
|
|
// attached to qHint to allow substitution / mocking
|
|
|
|
qHint.sendRequest = function (url, callback) {
|
|
|
|
var req = createXMLHTTPObject();
|
|
|
|
if (!req) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var method = "GET";
|
|
|
|
req.open(method,url + "?" + (new Date().getTime()),true);
|
|
|
|
req.onreadystatechange = function () {
|
|
|
|
if (req.readyState != 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(req);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req.send();
|
|
|
|
};
|
|
|
|
|
|
|
|
<%
|
2014-04-01 12:28:17 -04:00
|
|
|
TO_IGNORE = File.read("#{Rails.root}/.jshintignore").split("\n")
|
|
|
|
|
|
|
|
def jshint(dir, remove)
|
2013-06-21 14:06:20 -04:00
|
|
|
result = ""
|
|
|
|
|
|
|
|
Dir.glob(dir).each do |f|
|
2014-04-01 12:28:17 -04:00
|
|
|
filename = f.sub("#{Rails.root}/#{remove}", "")
|
2013-06-21 14:06:20 -04:00
|
|
|
|
|
|
|
ok = true
|
2014-04-01 12:28:17 -04:00
|
|
|
TO_IGNORE.each do |ig|
|
|
|
|
ok = false unless (filename.index(ig.sub(remove, '')).nil?)
|
2013-06-21 14:06:20 -04:00
|
|
|
end
|
|
|
|
|
2013-07-23 13:17:42 -04:00
|
|
|
depend_on filename
|
2013-12-31 12:41:40 -05:00
|
|
|
result << "qHint('#{filename}', '/assets/#{filename}', #{File.read(File.join(Rails.root, '.jshintrc'))});\n" if ok
|
2013-06-21 14:06:20 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
%>
|
|
|
|
|
2014-04-01 12:28:17 -04:00
|
|
|
<%= jshint("#{Rails.root}/test/**/*.js", "test/javascripts/") %>
|
|
|
|
<%= jshint("#{Rails.root}/app/assets/javascripts/**/*.js", "app/assets/javascripts/") %>
|
2013-06-21 14:06:20 -04:00
|
|
|
|
2014-05-05 12:47:20 -04:00
|
|
|
|