-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathangularity-reporter.js
More file actions
54 lines (48 loc) · 1.73 KB
/
angularity-reporter.js
File metadata and controls
54 lines (48 loc) · 1.73 KB
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
'use strict';
var through = require('through2');
/**
* A terse reporter for JSHint that uses the format as <code>traceurReporter</code>.
* Outputs elements from the input stream without transformation.
* @returns {stream.Through} A through stream that performs the operation of a gulp stream
*/
function angularityJshintReporter() {
var output = [];
var item = '';
var prevfile;
// push each item to an output buffer
return through.obj(function (file, encoding, done) {
if (file.jshint && !file.jshint.success && !file.jshint.ignored) {
(function reporter(results) {
results.forEach(function (result) {
var filename = result.file;
var error = result.error;
if ((prevfile) && (prevfile !== filename) && (item) && (output.indexOf(item) < 0)) {
output.push(item);
item = '';
}
item += filename + ':' + error.line + ':' + error.character + ': ' + error.reason + '\n';
prevfile = filename;
});
})(file.jshint.results, file.jshint.data);
}
// all elements to the output
this.push(file);
done();
// display the output buffer with padding before and after and between each item
}, function (done) {
if ((item) && (output.indexOf(item) < 0)) {
output.push(item);
}
if (output.length) {
var width = 80;
var hr = new Array(width + 1); // this is a good trick to repeat a character N times
var start = (width > 0) ? (hr.join('\u25BC') + '\n') : '';
var stop = (width > 0) ? (hr.join('\u25B2') + '\n') : '';
process.stdout.write(start + '\n' + output.join('\n') + '\n' + stop);
}
done();
});
}
module.exports = {
streamReporter: angularityJshintReporter
};