-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (32 loc) · 888 Bytes
/
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
'use strict';
const {relative} = require('path');
const xo = require('xo');
module.exports = {
name: 'xo',
every: false,
files: false,
* func(globs, opts) {
opts = Object.assign({quiet: false}, opts);
const report = yield xo.lintFiles(globs, opts);
// truncate project root from paths
let results = report.results.map(obj => {
obj.filePath = relative(this.root, obj.filePath);
return obj;
});
// hide warnings
if (opts.quiet) {
results = xo.getErrorResults(results);
}
if (report.errorCount > 0 || report.warningCount > 0) {
this.$.log(xo.getFormatter()(results));
}
if (report.errorCount > 0) {
const num = results.filter(el => el.errorCount > 0).length;
const end = (num > 1) ? 'files' : 'file';
this.emit('plugin_error', {
plugin: 'fly-xo',
error: `XO found ${report.errorCount} errors in ${num} ${end}!`
});
}
}
};