Skip to content

Commit

Permalink
jshint with checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
levsa committed Mar 25, 2013
1 parent 3baae0c commit fb142e5
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ targetCompatibility = '1.6'

defaultTasks 'clean', 'build'

version = '1.4.1'
version = '1.4.1-SNAPSHOT'
group = 'com.eriwen'
ext.archivesBaseName = 'gradle-js-plugin'
ext.isSnapshot = version.endsWith("-SNAPSHOT")
Expand Down
145 changes: 144 additions & 1 deletion src/main/resources/jshint-rhino-r12.js
Original file line number Diff line number Diff line change
Expand Up @@ -4834,13 +4834,151 @@ if (typeof exports === "object" && exports) {
/*jshint boss: true, rhino: true, unused: true, undef: true, white: true, quotmark: double */
/*global JSHINT*/


// Author: Boy Baukema
// http://github.com/relaxnow
var checkstyleReporter =
{
reporter: function (results, data)
{
"use strict";

var files = {},
out = [],
pairs = {
"&": "&",
'"': """,
"'": "'",
"<": "&lt;",
">": "&gt;"
},
file, fileName, i, issue, globals, unuseds;

function encode(s) {
for (var r in pairs) {
if (typeof(s) !== "undefined") {
s = s.replace(new RegExp(r, "g"), pairs[r]);
}
}
return s || "";
}

results.forEach(function (result) {
// Register the file
result.file = result.file.replace(/^\.\//, '');
if (!files[result.file]) {
files[result.file] = [];
}

// Add the error
files[result.file].push({
severity: 'error',
line: result.error.line,
column: result.error.character,
message: result.error.reason,
source: result.error.raw
});
});

data.forEach(function (result) {
file = data.file;
globals = result.implieds;
unuseds = result.unused;

// Register the file
result.file = result.file.replace(/^\.\//, '');
if (!files[result.file]) {
files[result.file] = [];
}

if (globals) {
globals.forEach(function (global) {
files[result.file].push({
severity: 'warning',
line: global.line,
column: 0,
message: "Implied global '" + global.name + "'",
source: 'jshint.implied-globals'
});
});
}
if (unuseds) {
unuseds.forEach(function (unused) {
files[result.file].push({
severity: 'warning',
line: unused.line,
column: 0,
message: "Unused variable: '" + unused.name + "'",
source: 'jshint.implied-unuseds'
});
});
}
});

out.push("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.push("<checkstyle version=\"4.3\">");

for (fileName in files) {
if (files.hasOwnProperty(fileName)) {
out.push("\t<file name=\"" + fileName + "\">");
for (i = 0; i < files[fileName].length; i++) {
issue = files[fileName][i];
out.push(
"\t\t<error " +
"line=\"" + issue.line + "\" " +
"column=\"" + issue.column + "\" " +
"severity=\"" + issue.severity + "\" " +
"message=\"" + encode(issue.message) + "\" " +
"source=\"" + encode(issue.source) + "\" " +
"/>"
);
}
out.push("\t</file>");
}
}

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

if (typeof process !== "undefined") {
process.stdout.write(out.join("\n") + "\n");
} else {
print(out.join("\n") + "\n");
}
}
};

var reportWithReporter = function (reporter, file) {
var results = [];
var data = [];
var lintData;

JSHINT.errors.forEach(function (err) {
if (err) {
results.push({ file: file, error: err });
}
});

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

if (reporter) {
reporter(results, data, { verbose: true});
}

};

(function (args) {
var filenames = [];
var optstr; // arg1=val1,arg2=val2,...
var predef; // global1=true,global2,global3,...
var opts = {};
var retval = 0;

print("Calling rhino with: " + args.join(", "));

args.forEach(function (arg) {
if (arg.indexOf("=") > -1) {
if (!optstr) {
Expand Down Expand Up @@ -4904,12 +5042,17 @@ if (typeof exports === "object" && exports) {
}

if (!JSHINT(input, opts)) {
if (checkstyleReporter) {
reportWithReporter(checkstyleReporter.reporter, name);
}
else {
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("");
}
retval = 1;
}
retval = 1;
}
});

Expand Down

0 comments on commit fb142e5

Please sign in to comment.