-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjshint-reporter.js
63 lines (47 loc) · 1.73 KB
/
jshint-reporter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var fs = require("fs");
var gutil = require("gulp-util");
var through = require("through2");
module.exports = function (options) {
options = options || {};
var out = options.out || "jshint.json";
var result = undefined;
var collectResult = function (value, encoding, callback) {
if (value.isNull()) {
this.push(value);
return callback();
}
if (value.isStream()) {
this.emit("error", gutil.PluginError("gulp-jshintreporter", "Streaming not supported."));
return callback();
}
var jshint = value.jshint;
if (result === undefined) {
result = {"success": jshint.success, "errors": jshint.results || []};
return callback();
}
result.success = result.success && jshint.success;
result.errors = jshint.results ? result.errors.concat(jshint.results) : result.errors;
return callback();
};
var summarizeResults = function (callback) {
if (result === undefined) {
return callback();
}
var i, len;
var output = {};
for (i = 0, len = result.errors.length; i < len; ++i) {
var error = result.errors[i];
if (!output.hasOwnProperty(error.file)) {
output[error.file] = {errors: []};
}
output[error.file].errors.push(error.error);
}
fs.writeFile(out, JSON.stringify(output), function (error) {
if (error) {
this.emit("error", gutil.PluginError("gulp-jshintreporter", "Report file [" + out + "] could not be written."));
}
});
return callback();
};
return through.obj(collectResult, summarizeResults);
};