disableOptionsReportStringFormatter.js 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const chalk = require('chalk');
  3. const path = require('path');
  4. /**
  5. * @param {string} fromValue
  6. * @return {string}
  7. */
  8. function logFrom(fromValue) {
  9. if (fromValue.startsWith('<')) return fromValue;
  10. return path.relative(process.cwd(), fromValue).split(path.sep).join('/');
  11. }
  12. /**
  13. * @param {import('stylelint').StylelintDisableOptionsReport} report
  14. * @param {string} message
  15. * @returns {string}
  16. */
  17. module.exports = function (report, message) {
  18. if (!report) return '';
  19. let output = '';
  20. report.forEach((sourceReport) => {
  21. if (!sourceReport.ranges || sourceReport.ranges.length === 0) {
  22. return;
  23. }
  24. output += '\n';
  25. // eslint-disable-next-line prefer-template
  26. output += chalk.underline(logFrom(sourceReport.source || '')) + '\n';
  27. sourceReport.ranges.forEach((range) => {
  28. output += `${message}: ${range.rule}, start line: ${range.start}`;
  29. if (range.end !== undefined) {
  30. output += `, end line: ${range.end}`;
  31. }
  32. output += '\n';
  33. });
  34. });
  35. return output;
  36. };