Skip to content

Commit

Permalink
Fail when JSLint fails and lint.failonerror=true.
Browse files Browse the repository at this point in the history
  • Loading branch information
reid committed Jun 20, 2010
1 parent c76f065 commit 1ece969
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
33 changes: 22 additions & 11 deletions componentbuild/lib/jslint/jslint-node.js
Expand Up @@ -20,10 +20,9 @@ JSLINT = require("./fulljslint").JSLINT;
};

function test(js) {
if (!js) throw new Error("No JS provided");
var body = "", code = 200;

var body = "";
var success = JSLINT(js, OPTS);
var success = JSLINT(js, OPTS);
if (success) {
return "OK";
} else {
Expand All @@ -34,7 +33,15 @@ JSLINT = require("./fulljslint").JSLINT;
}
}
body += "\n";
return body;

// Last item is null if JSLint hit a fatal error
if (JSLINT.errors && JSLINT.errors[JSLINT.errors.length-1] === null) {
code = 500;
}
return {
"content" : body,
"code" : code
};
}
}

Expand Down Expand Up @@ -73,16 +80,20 @@ JSLINT = require("./fulljslint").JSLINT;
var die = "/kill" === req.url;
if (die) body = "Goodbye.";
else if (req.method === "POST") {
var files = qs.parse(data)["files"].split("' '");
var query = qs.parse(data);
var files = query["files"].split("' '");
var failOnError = query["failonerror"] == "true";
var results = [];
files.forEach(function (file) {
fs.readFile(file, function (err, data) {
data = data.toString("utf8");
try {
results.push(test(data));
} catch (ex) {
proc.emit("end", 500, err.message);
}
var diagnosis = test(data.toString("utf8"));
results.push(diagnosis.content);

code = (
failOnError &&
diagnosis.code !== 200
) ? diagnosis.code : code;

if (results.length == files.length) proc.emit("end", code, results.join("\n"));
});
});
Expand Down
15 changes: 14 additions & 1 deletion componentbuild/shared/macrolib.xml
Expand Up @@ -141,9 +141,22 @@
</or>
<then>
<property name="node.online" value="true"/>
<post to="${node.jslint.url}" failonerror="${lint.failonerror}">
<post to="${node.jslint.url}" property="node.jslint.response" failonerror="${lint.failonerror}">
<prop name="files" value="${jsfileargs}"/>
<prop name="failonerror" value="${lint.failonerror}"/>
</post>
<!-- Since Ant doesn't really failonerror for the post task,
handle this ourselves: -->
<if>
<not>
<isset property="node.jslint.response"/>
</not>
<then>
<fail>JSLint failed. To view lint output and continue the build, run ant with -Dlint.failonerror=false.</fail>
</then>
</if>
<!-- Clear property for next run: -->
<var name="node.jslint.response" unset="true"/>
</then>
<else>
<echo>Using Rhino. Install nodejs to improve jslint speed, or skip with -Dlint.skip=true</echo>
Expand Down

0 comments on commit 1ece969

Please sign in to comment.