githubFormatter.cjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const preprocessWarnings = require('./preprocessWarnings.cjs');
  5. /**
  6. * @see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
  7. *
  8. * @type {import('stylelint').Formatter}
  9. *
  10. * @deprecated See https://stylelint.io/awesome-stylelint#formatters for alternative formatters.
  11. */
  12. function githubFormatter(results, returnValue) {
  13. const title = 'Stylelint problem';
  14. const metadata = returnValue.ruleMetadata;
  15. const lines = results.flatMap((result) => {
  16. const { source, warnings } = preprocessWarnings(result);
  17. return warnings.map(({ line, column, endLine, endColumn, text, severity, rule }) => {
  18. const msg = buildMessage(text, metadata[rule]);
  19. return endLine === undefined
  20. ? `::${severity} file=${source},line=${line},col=${column},title=${title}::${msg}`
  21. : `::${severity} file=${source},line=${line},col=${column},endLine=${endLine},endColumn=${endColumn},title=${title}::${msg}`;
  22. });
  23. });
  24. lines.push(`::notice title=Stylelint deprecation::The github formatter is deprecated`);
  25. lines.push('');
  26. return lines.join('\n');
  27. }
  28. /**
  29. * @param {string} msg
  30. * @param {Partial<import('stylelint').RuleMeta> | undefined} metadata
  31. * @returns {string}
  32. */
  33. function buildMessage(msg, metadata) {
  34. if (!metadata) return msg;
  35. const url = metadata.url ? ` - ${metadata.url}` : '';
  36. let additional = [
  37. metadata.fixable ? 'maybe fixable' : '',
  38. metadata.deprecated ? 'deprecated' : '',
  39. ]
  40. .filter(Boolean)
  41. .join(', ');
  42. additional = additional ? ` [${additional}]` : '';
  43. return `${msg}${additional}${url}`;
  44. }
  45. module.exports = githubFormatter;