1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
6 |
|
7 | var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
8 |
|
9 | var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
10 |
|
11 | var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
12 |
|
13 | var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
14 |
|
15 | function _wrapRegExp(re, groups) { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _RegExp = (0, _wrapNativeSuper2.default)(RegExp); var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = _RegExp.call(this, re, flags); _groups.set(_this, groups || _groups.get(re)); return _this; } (0, _inherits2.default)(BabelRegExp, _RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = []; args.push.apply(args, arguments); if ((0, _typeof2.default)(args[args.length - 1]) !== "object") { args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
|
16 |
|
17 | var os = require('os');
|
18 |
|
19 | var chalk = require('chalk');
|
20 |
|
21 | var stripAnsi = require('strip-ansi');
|
22 |
|
23 | var table = require('text-table');
|
24 |
|
25 | function pluralize(word, count) {
|
26 | return count === 1 ? word : "".concat(word, "s");
|
27 | }
|
28 |
|
29 | module.exports = function (results) {
|
30 | var output = os.EOL;
|
31 | var errorCount = 0;
|
32 | var warningCount = 0;
|
33 | var fixableErrorCount = 0;
|
34 | var fixableWarningCount = 0;
|
35 | var summaryColor = 'yellow';
|
36 | results.forEach(function (result) {
|
37 | var messages = result.messages;
|
38 |
|
39 | if (messages.length === 0) {
|
40 | return;
|
41 | }
|
42 |
|
43 | errorCount += result.errorCount;
|
44 | warningCount += result.warningCount;
|
45 | fixableErrorCount += result.fixableErrorCount;
|
46 | fixableWarningCount += result.fixableWarningCount;
|
47 | output += table(messages.map(function (message) {
|
48 | var messageType;
|
49 |
|
50 | if (message.fatal || message.severity === 2) {
|
51 | messageType = chalk.red('error');
|
52 | summaryColor = 'red';
|
53 | } else {
|
54 | messageType = chalk.yellow('warning');
|
55 | }
|
56 |
|
57 | return ['', message.line || 0, message.column || 0, messageType, message.message.replace(_wrapRegExp(/([\0-\x1F!-\uFFFF])\.$/, {
|
58 | msg: 1
|
59 | }), '$1'), chalk.dim(message.ruleId || '')];
|
60 | }), {
|
61 | align: ['', 'r', 'l'],
|
62 | stringLength: function stringLength(str) {
|
63 | return stripAnsi(str).length;
|
64 | }
|
65 | }).split(os.EOL).map(function (el) {
|
66 | return el.replace(_wrapRegExp(/([0-9]+)[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+([0-9]+)/, {
|
67 | line: 1,
|
68 | column: 2
|
69 | }), function (m, p1, p2) {
|
70 | return chalk.dim("".concat(p1, ":").concat(p2));
|
71 | });
|
72 | }).join(os.EOL) + os.EOL;
|
73 | });
|
74 | var total = errorCount + warningCount;
|
75 |
|
76 | if (total > 0) {
|
77 | if (fixableErrorCount > 0 || fixableWarningCount > 0) {
|
78 | output += os.EOL +
|
79 | chalk[summaryColor].bold([' ', fixableErrorCount, pluralize(' error', fixableErrorCount), ' and ', fixableWarningCount, pluralize(' warning', fixableWarningCount), ' potentially fixable with the `--fix` option.\n'].join(''));
|
80 | }
|
81 | }
|
82 |
|
83 | return total > 0 ? output : '';
|
84 | }; |
\ | No newline at end of file |