Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withcs #966

Closed
wants to merge 11 commits into from
20 changes: 19 additions & 1 deletion make.js
Expand Up @@ -112,8 +112,25 @@ target.build = function () {

bundle.append("JSHINT = require('/src/stable/jshint.js').JSHINT;");

var fakeConsole = "if (typeof console === \"undefined\") {" + "\n" +
" var console = {" + "\n" +
" error: function (txt) {" + "\n" +
" if (typeof Packages !== \"undefined\") { // rhino" + "\n" +
" java.lang.System.err.println('CONSOLE.error: ' + txt);" + "\n" +
" }" + "\n" +
" }," + "\n" +
" trace: function () {" + "\n" +
" }" + "\n" +
" };" + "\n" +
"}" + "\n";

bundle.addEntry("./src/reporters/checkstyle.js");
bundle.append("checkstyleReporter = require('./src/reporters/checkstyle.js').reporter;");

[ "// " + pkg.version,
"var JSHINT;",
"var checkstyleReporter;",
fakeConsole,
bundle.bundle()
].join("\n").to("./dist/jshint-" + pkg.version + ".js");

Expand All @@ -126,4 +143,5 @@ target.build = function () {
exec("chmod +x dist/jshint-rhino-" + pkg.version + ".js");
cli.ok("Rhino");
echo("\n");
};

};
5 changes: 2 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jshint",
"version": "1.1.0",
"version": "1.1.1",
"homepage": "http://jshint.com/",
"description": "Static analysis tool for JavaScript",

Expand Down Expand Up @@ -36,8 +36,7 @@
"browserify": "1.16.1",
"coveraje": "0.2.x",
"nodeunit": "0.7.x",
"sinon": "1.6.x",
"console-browserify": "0.1.x"
"sinon": "1.6.x"
},

"preferGlobal": true
Expand Down
55 changes: 42 additions & 13 deletions src/platforms/rhino.js
@@ -1,17 +1,27 @@
/*jshint boss: true, rhino: true, unused: true, undef: true, white: true, quotmark: double */
/*global JSHINT */
/*global checkstyleReporter */

(function (args) {
"use strict";

var filenames = [];
var optstr; // arg1=val1,arg2=val2,...
var reporter; // only "checkstyle" is recognized
var optstr; // arg1=val1,arg2=val2,... or reporter=<reporter>
var predef; // global1=true,global2,global3,...
var opts = {};
var retval = 0;

var results = [];
var data = [];
var lintData;

args.forEach(function (arg) {
if (arg.indexOf("=") > -1) {
// Check first for reporter option
if (arg.split("=")[0] === "reporter") {
reporter = arg.split("=")[1];
return;
}
if (!optstr) {
// First time it's the options.
optstr = arg;
Expand Down Expand Up @@ -64,23 +74,42 @@
});
}

filenames.forEach(function (name) {
var input = readFile(name);

filenames.forEach(function (file) {
var input = readFile(file);
if (!input) {
print("jshint: Couldn't open file " + name);
print("jshint: Couldn't open file " + file);
quit(1);
}

if (!JSHINT(input, opts)) {
for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
print(err.reason + " (" + name + ":" + err.line + ":" + err.character + ")");
print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
print("");
}
JSHINT.errors.forEach(function (err) {
if (err) {
results.push({ file: file, error: err });
}
});
retval = 1;
}

lintData = JSHINT.data();

if (lintData) {
lintData.file = file;
data.push(lintData);
}
});

if (reporter === "checkstyle" && typeof checkstyleReporter !== "undefined") {
checkstyleReporter(results, data);
} else {
for (var i = 0; i < results.length; i += 1) {
var file = results[i].file;
var err = results[i].error;
print(err.reason + " (" + file + ":" + err.line + ":" + err.character + ")");
print("> " + (err.evidence || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
print("");
}
}

quit(retval);
}(arguments));
7 changes: 6 additions & 1 deletion src/reporters/checkstyle.js
@@ -1,5 +1,6 @@
// Author: Boy Baukema
// http://github.com/relaxnow
/*global print*/
module.exports =
{
reporter: function (results, data)
Expand Down Expand Up @@ -102,6 +103,10 @@ module.exports =

out.push("</checkstyle>");

process.stdout.write(out.join("\n") + "\n");
if (typeof process !== "undefined" && process.stdout) {
process.stdout.write(out.join("\n") + "\n");
} else {
print(out.join("\n") + "\n");
}
}
};
7 changes: 0 additions & 7 deletions src/stable/jshint.js
Expand Up @@ -29,8 +29,6 @@
*/

/*jshint quotmark:double */
/*global console:true */
/*exported console */

var _ = require("underscore");
var events = require("events");
Expand All @@ -41,11 +39,6 @@ var reg = require("./reg.js");
var state = require("./state.js").state;
var style = require("./style.js");

// We need this module here because environments such as IE and Rhino
// don't necessarilly expose the 'console' API and browserify uses
// it to log things. It's a sad state of affair, really.
var console = require("console-browserify");

// We build the application inside a function so that we produce only a singleton
// variable. That function will be invoked immediately, and its return value is
// the JSHINT function itself.
Expand Down