UNPKG

1.01 kBJavaScriptView Raw
1'use strict';
2
3const chalk = require('chalk');
4const path = require('path');
5
6/**
7 * @param {string} fromValue
8 * @return {string}
9 */
10function logFrom(fromValue) {
11 if (fromValue.startsWith('<')) return fromValue;
12
13 return path.relative(process.cwd(), fromValue).split(path.sep).join('/');
14}
15
16/**
17 * @param {import('stylelint').StylelintDisableOptionsReport} report
18 * @param {string} message
19 * @returns {string}
20 */
21module.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 // eslint-disable-next-line prefer-template
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};