-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (49 loc) · 1.44 KB
/
Copy pathindex.js
File metadata and controls
59 lines (49 loc) · 1.44 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
55
56
57
58
59
'use strict'
var through2 = require('through2')
var standard = require('standard')
var PluginError = require('plugin-error')
var PLUGIN_NAME = require('./package.json').name
var defaultReporter = require('./reporters/stylish')
function gulpStandard (opts) {
function processFile (file, enc, cb) {
if (file.isNull()) {
return cb(null, file)
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streams are not supported!'))
}
standard.lintText(String(file.contents), Object.assign({
filename: file.path
}, opts), function (err, data) {
if (err) {
return cb(err)
}
file.standard = data
if (data.results[0] && data.results[0].output) {
file.contents = Buffer.from(data.results[0].output)
data.fixed = true
}
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-standard/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