1 | 'use strict';
|
2 |
|
3 | const chalk = require('chalk');
|
4 | const path = require('path');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function logFrom(fromValue) {
|
11 | if (fromValue.startsWith('<')) return fromValue;
|
12 |
|
13 | return path.relative(process.cwd(), fromValue).split(path.sep).join('/');
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | module.exports = function (report, message) {
|
22 | if (!report) return '';
|
23 |
|
24 | let output = '';
|
25 |
|
26 | report.forEach((sourceReport) => {
|
27 | if (!sourceReport.ranges || sourceReport.ranges.length === 0) {
|
28 | return;
|
29 | }
|
30 |
|
31 | output += '\n';
|
32 |
|
33 | output += chalk.underline(logFrom(sourceReport.source || '')) + '\n';
|
34 |
|
35 | sourceReport.ranges.forEach((range) => {
|
36 | output += `${message}: ${range.rule}, start line: ${range.start}`;
|
37 |
|
38 | if (range.end !== undefined) {
|
39 | output += `, end line: ${range.end}`;
|
40 | }
|
41 |
|
42 | output += '\n';
|
43 | });
|
44 | });
|
45 |
|
46 | return output;
|
47 | };
|