-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (38 loc) · 1.07 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
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var gherkin = require('gherkin');
var chalk = require('chalk');
var PLUGIN_NAME = 'gulp-gherkin-lint';
module.exports = function () {
var parser = new gherkin.Parser();
var errors = [];
var stream = through.obj(parse, report);
function parse(file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
return callback(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
try {
parser.parse(file.contents.toString('utf8'));
stream.push(file);
return callback();
} catch (e) {
var pluginError = chalk.red(e.message) + '\nat: ' + chalk.cyan(file.path);
errors.push(pluginError);
}
return callback();
}
function report(callback) {
if (errors.length > 0) {
stream.emit('error', new gutil.PluginError(PLUGIN_NAME, {
message: '\n' + errors.join('\n'),
showStack: false
}));
}
callback();
}
return stream;
};