-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwsh-jslint-runner.js
37 lines (37 loc) · 1.21 KB
/
wsh-jslint-runner.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
/*global ActiveXObject: false, WScript: false*/
/*jslint evil: true*/
(function () {
'use strict';
var filename, i, e,
fso = new ActiveXObject('Scripting.FileSystemObject'),
options = {},
tool = this.JSLINT,
exit = function (msg) {
WScript.StdOut.WriteLine(msg);
WScript.Quit();
};
if (!tool) {
exit('jslint.js not found.');
}
if (WScript.Arguments.length === 0) {
exit('No filename provided.');
}
filename = WScript.Arguments(0);
if (!fso.FileExists(filename)) {
exit('File "' + filename + '" not found.');
}
if (fso.FileExists('options.js')) {
// Ideally this would use JSON.parse instead of eval but I haven't yet figured how to get the JSON object in a WSH script.
eval('options = ' + fso.openTextFile('options.js', 1, false, -2).ReadAll() + ';');
}
if (!tool(fso.OpenTextFile(filename, 1, false, -2).ReadAll(), options)) {
for (i = 0; i < tool.errors.length; i = i + 1) {
e = tool.errors[i];
if (e) {
WScript.StdOut.WriteLine('JSLint at line ' + e.line + ' character ' + e.character + ': ' + e.reason);
WScript.StdOut.WriteLine((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, '$1')); // the regex trims leading/trailing whitespace
WScript.StdOut.WriteLine();
}
}
}
}());