forked from nebez/gulp-semistandard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (45 loc) · 1.33 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
'use strict';
var through2 = require('through2');
var semistandard = require('semistandard');
var gutil = require('gulp-util');
var PLUGIN_NAME = require('./package.json').name;
var defaultReporter = require('./reporters/stylish');
function gulpStandard (opts) {
opts = opts || {};
function processFile (file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streams are not supported!'));
return cb();
}
semistandard.lintText(String(file.contents), opts, function (err, data) {
if (err) {
return cb(err);
}
file.standard = data;
cb(null, file);
});
}
return through2.obj(processFile);
}
gulpStandard.reporter = function (reporter, opts) {
// Load default reporter
if (reporter === 'default') return defaultReporter(opts);
// Load reporter from function
if (typeof reporter === 'function') return reporter(opts);
// load built-in reporters
if (typeof reporter === 'string') {
try {
return require('gulp-semistandard/reporters/' + reporter)(opts);
} catch (err) {}
}
// load full-path or module reporters
if (typeof reporter === 'string') {
try {
return require(reporter)(opts);
} catch (err) {}
}
};
module.exports = gulpStandard;