-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (29 loc) · 919 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
'use strict';
const p = require('path');
const xo = require('xo');
module.exports = function (task, utils) {
task.plugin('xo', { every:false, files:false }, function * (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 = p.relative(task.root, obj.filePath);
return obj;
});
// hide warnings
if (opts.quiet) {
results = xo.getErrorResults(results);
}
if (report.errorCount > 0 || report.warningCount > 0) {
utils.log(xo.getFormatter()(results));
}
if (report.errorCount > 0) {
const num = results.filter(el => el.errorCount > 0).length;
const end = (num > 1) ? 'files' : 'file';
task.emit('plugin_error', {
plugin: '@taskr/xo',
error: `XO found ${report.errorCount} errors in ${num} ${end}!`
});
}
});
};