-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
69 lines (54 loc) · 1.64 KB
/
index.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
64
65
66
67
68
69
'use strict';
var TransformStream = require('stream').Transform;
function gulpEslintThreshold() {
}
/**
* Count the warnings in the ESLint result, then call a callback function if the threshold is met
*/
gulpEslintThreshold.afterWarnings = function(minWarnings, callback) {
var stream = new TransformStream({
objectMode: true
}),
eslintWarnings = 0;
stream._transform = function(chunk, encoding, done) {
var messages = chunk.eslint && chunk.eslint.messages || [];
messages.some(function(message) {
if(message.severity === 1) { // 1 warning, 2 error
eslintWarnings++;
}
});
return done(null, chunk);
};
stream._flush = function(done) {
// Call the callback function if the number of warnings found by ESLint is equal to or greater than minWarnings
if(eslintWarnings >= minWarnings && typeof callback === 'function') {
callback(eslintWarnings);
}
done();
};
return stream;
};
gulpEslintThreshold.afterErrors = function(minErrors, callback) {
var stream = new TransformStream({
objectMode: true
}),
eslintErrors = 0;
stream._transform = function(chunk, encoding, done) {
var messages = chunk.eslint && chunk.eslint.messages || [];
messages.some(function(message) {
if(message.severity === 2) { // 1 warning, 2 error
eslintErrors++;
}
});
return done(null, chunk);
};
stream._flush = function(done) {
// Call the callback function if the number of errors found by ESLint is equal to or greater than minErrors
if(eslintErrors >= minErrors && typeof callback === 'function') {
callback(eslintErrors);
}
done();
};
return stream;
};
module.exports = gulpEslintThreshold;