forked from sindresorhus/jshint-stylish
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstylish.js
71 lines (59 loc) · 1.73 KB
/
stylish.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
var chalk = require('chalk');
var table = require('text-table');
var logSymbols = require('log-symbols');
var stringLength = require('string-length');
function pluralize(str, count) {
return str + (count === 1 ? '' : 's');
}
module.exports = {
reporter: function (result, config, options) {
var total = result.length;
var ret = '';
var headers = [];
var prevfile;
var errorCount = 0;
var warningCount = 0;
options = options || {};
ret += table(result.map(function (el, i) {
var err = el.error;
// E: Error, W: Warning, I: Info
var isError = err.code && err.code[0] === 'E';
var line = [
chalk.gray(err.id),// .slice(1,-4) // remove first and last char
chalk.blue('jshint -' + err.code),
chalk.gray('line'),
chalk.blue(err.line),
chalk.gray(':' + err.character),
chalk.green(err.reason)
];
if (el.file !== prevfile) {
headers[i] = el.file;
}
if (options.verbose) {
line.push(chalk.gray('(' + err.code + ')'));
}
if (isError) {
errorCount++;
} else {
warningCount++;
}
prevfile = el.file;
return line;
}), {
stringLength: stringLength
}).split('\n').map(function (el, i) {
return headers[i] ? '\n' + chalk.underline(headers[i]) + '\n' + el : el;
}).join('\n') + '\n\n';
if (total > 0) {
if (errorCount > 0) {
ret += ' ' + logSymbols.error + ' ' + errorCount + pluralize(' error', errorCount) + (warningCount > 0 ? '\n' : '');
}
ret += ' ' + logSymbols.warning + ' ' + warningCount + pluralize(' warning', total);
} else {
ret += ' ' + logSymbols.success + ' No problems';
ret = '\n' + ret.trim();
}
console.log(ret + '\n');
}
};