Skip to content

Commit

Permalink
added windows build system.
Browse files Browse the repository at this point in the history
Hightly untested but seems to work.
  • Loading branch information
smithamax committed Jun 25, 2011
1 parent 30264cb commit a985cc7
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 0 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions jshint(Windows).sublime-build
@@ -0,0 +1,6 @@
{
"cmd": ["$packages/JSHint/jshint.bat", "$file"],
"file_regex": "^\\s+[0-9]+\\s+([^:]+):([0-9]+),",
"line_regex": "([0-9]+),[0-9]+",
"selector": "source.js"
}
3 changes: 3 additions & 0 deletions jshint.bat
@@ -0,0 +1,3 @@
setlocal
for %%F in (%0) do set dirname=%%~dpF
cscript "%dirname%jshint.wsh.js" %1
168 changes: 168 additions & 0 deletions jshint.wsh.js
@@ -0,0 +1,168 @@
/*jshint evil: true, shadow: true, wsh: true */
/*global JSHINT: false */

(function() {
function readFile(path) {
try {
return new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(path, 1).ReadAll();
} catch (ex) {
return null;
}
}

var formatters = {
errors: function(errors, lines) {
for (var i = 0; i < errors.length; i++) {
var error = errors[i];

if (!error) continue;

if (i) lines.push("");

lines.push("Line " + error.line + " character " + error.character + ": " + error.reason);

if (error.evidence) lines.push(" " + error.evidence.replace(/^\s*((?:[\S\s]*\S)?)\s*$/, "$1"));
}
},

implieds: function(implieds, lines) {
lines.push("Implied globals:");

var globals = {};

for (var i = 0; i < implieds.length; i++) {
var item = implieds[i];

if (!(item.name in globals)) globals[item.name] = [];

globals[item.name].push(item.line);
}

for (var name in globals) {
lines.push(" " + name + ": " + globals[name].join(", "));
}
},

unused: function(unused, lines) {
lines.push("Unused variables:");

var func, names = {};

for (var i = 0; i < unused.length; i++) {
var item = unused[i];

func = item["function"];

if (!(func in names)) names[func] = [];

names[func].push(item.name + " (" + item.line + ")");
}

for (func in names) {
lines.push(" " + func + ": " + names[func].join(", "));
}
}
};

var scriptName = WScript.ScriptName;
var scriptPath = WScript.ScriptFullName;

scriptPath = scriptPath.substr(0, scriptPath.length - scriptName.length);

// load JSHint if the two scripts have not been concatenated
if (typeof JSHINT === "undefined") {
eval(readFile(scriptPath + "jshint.js"));

if (typeof JSHINT === "undefined") {
WScript.StdOut.WriteLine("ERROR: Could not find 'jshint.js'.");

WScript.Quit(-2);
}
}

var globals = {};
var options = {};
var named = WScript.Arguments.Named;
var unnamed = WScript.Arguments.Unnamed;

if (unnamed.length !== 1) {
WScript.StdOut.WriteLine(" usage: cscript " + scriptName + " [options] <script>");
WScript.StdOut.WriteLine("");
WScript.StdOut.WriteLine("Scans the specified script with JSHint and reports any errors encountered. If");
WScript.StdOut.WriteLine("the script name is \"-\", it will be read from standard input instead.");
WScript.StdOut.WriteLine("");
WScript.StdOut.WriteLine("JSHint configuration options can be passed in via optional, Windows-style");
WScript.StdOut.WriteLine("arguments. For example:");
WScript.StdOut.WriteLine(" cscript " + scriptName + " /jquery:true myscript.js");
WScript.StdOut.WriteLine(" cscript " + scriptName + " /globals:QUnit:false,_:false,foo:true foo.js");

WScript.Quit(-1);
}

var script = unnamed(0);

if (script === "-") {
try {
script = WScript.StdIn.ReadAll();
} catch (ex) {
script = null;
}
} else {
script = readFile(script);
}

if (script === null) {
WScript.StdOut.WriteLine("ERROR: Could not read target script.");

WScript.Quit(2);
}

for (var etor = new Enumerator(named); !etor.atEnd(); etor.moveNext()) {
var option = etor.item();
var value = named(option);

if (option === "global") {
value = value.split(",");

for (var i = 0; i < value.length; i++) {
var name = value[i].split(":");

if (name.length === 1 || name[1] === "false") {
globals[name[0]] = false;
} else if (name[1] === "true") {
globals[name[0]] = true;
} else {
WScript.StdOut.WriteLine("Unrecognized value for global: " + name[0]);
WScript.StdOut.WriteLine("Must be \"true\", \"false\", or omitted.");

WScript.Quit(-1);
}
}
} else {
options[option] = value === "true" ? true : value === "false" ? false : value;
}
}

JSHINT(script, options, globals);

var data = JSHINT.data();
var lines = [];

for (var formatter in formatters) {
if (data[formatter]) {
if (lines.length) lines.push("");

formatters[formatter](data[formatter], lines);
}
}

if (lines.length) {
for (var i = 0; i < lines.length; i++) {
WScript.StdOut.WriteLine(lines[i]);
}

WScript.Quit(1);
} else {
WScript.Quit(0);
}
}());

0 comments on commit a985cc7

Please sign in to comment.