This repository was archived by the owner on Nov 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (52 loc) · 1.31 KB
/
index.js
File metadata and controls
64 lines (52 loc) · 1.31 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
60
61
62
63
64
'use strict';
const eslint = require('gulp-eslint');
const formatterPretty = require('eslint-formatter-pretty');
const through = require('through2');
const xo = require('xo');
const PluginError = require('plugin-error');
module.exports = options => {
options = {
quiet: false,
...options
};
return through.obj(function (file, encoding, callback) {
if (file.isNull()) {
callback(null, file);
return;
}
if (file.isStream()) {
callback(new PluginError('gulp-xo', 'Streaming not supported'));
return;
}
let report;
try {
report = xo.lintText(file.contents.toString(), {
...options,
cwd: file.cwd,
filename: file.path
});
} catch (error) {
this.emit('error', new PluginError('gulp-xo', error, {fileName: file.path}));
}
let result = report.results;
if (result.length === 0) {
callback(null, file);
return;
}
if (options.quiet) {
result = xo.getErrorResults(result);
}
file.eslint = result[0];
if (file.eslint.output) {
file.contents = Buffer.from(file.eslint.output);
file.eslint.fixed = true;
}
callback(null, file);
});
};
Object.assign(module.exports, eslint);
for (const fn of ['formatEach', 'format']) {
module.exports[fn] = (formatter, writable) => (
eslint[fn](formatter ? xo.getFormatter(formatter) : formatterPretty, writable)
);
}