UNPKG

982 BJavaScriptView 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 * @returns {string}
19 */
20module.exports = function (report) {
21 if (!report) return '';
22
23 let output = '';
24
25 report.forEach((sourceReport) => {
26 if (!sourceReport.ranges || sourceReport.ranges.length === 0) {
27 return;
28 }
29
30 output += '\n';
31 // eslint-disable-next-line prefer-template
32 output += chalk.underline(logFrom(sourceReport.source || '')) + '\n';
33
34 sourceReport.ranges.forEach((range) => {
35 output += `unused rule: ${range.unusedRule}, start line: ${range.start}`;
36
37 if (range.end !== undefined) {
38 output += `, end line: ${range.end}`;
39 }
40
41 output += '\n';
42 });
43 });
44
45 return output;
46};