-
Notifications
You must be signed in to change notification settings - Fork 8
/
qhint-1.1.js
88 lines (76 loc) · 2.6 KB
/
qhint-1.1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*! qHint 1.1 | http://gyoshev.mit-license.org */
(function() {
var qHint =
window.jsHintTest =
window.qHint =
function qHint(name, sourceFile, options, globals) {
if (sourceFile === undefined || typeof(sourceFile) == "object") {
// jsHintTest('file.js', [options])
globals = options;
options = sourceFile;
sourceFile = name;
}
return asyncTest(name, function() {
qHint.sendRequest(sourceFile, function(req) {
start();
if (req.status == 200) {
qHint.validateFile(req.responseText, options, globals);
} else {
ok(false, "HTTP error " + req.status +
" while fetching " + sourceFile);
}
});
});
};
qHint.validateFile = function (source, options, globals) {
var i, len, err;
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,true);
req.onreadystatechange = function () {
if (req.readyState != 4) {
return;
}
callback(req);
};
if (req.readyState == 4) {
return;
}
req.send();
};
})();