UNPKG

1.24 kBJavaScriptView Raw
1var table = require('text-table');
2var chalk = require('chalk');
3var logSymbols = require('log-symbols');
4
5function outputFooter(output) {
6 var total = output.length;
7 var msg = total + ' problem' + (total === 1 ? '' : 's');
8 console.log('\n', logSymbols.error, msg);
9}
10
11function outputJSON(output) {
12 console.log(JSON.stringify(output, null, 2));
13 outputFooter(output);
14}
15
16function outputTable(results) {
17 var headers = [];
18 var prevfile;
19 var t = table(results.map(function (el, i) {
20 var line = ['',
21 chalk.gray('line ' + el.loc.start.line),
22 chalk.gray('col ' + el.loc.start.column),
23 el.value,
24 chalk.cyan(el.code)
25 ];
26 if (el.file !== prevfile) {
27 headers[i] = el.file;
28 }
29 prevfile = el.file;
30 return line;
31 }, {
32 stringLength: function (str) {
33 return chalk.stripColor(str).length;
34 }
35 }));
36
37 //set filename headers
38 t = t.split('\n').map(function (el, i) {
39 return headers[i] ? '\n' + chalk.underline(headers[i]) + '\n' + el : el;
40 }).join('\n');
41 console.log(t);
42 outputFooter(results);
43}
44
45exports.reporters = {
46 json: outputJSON,
47 table: outputTable
48};