tapFormatter.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const preprocessWarnings = require('./preprocessWarnings');
  3. /**
  4. * @type {import('stylelint').Formatter}
  5. */
  6. module.exports = function tapFormatter(results) {
  7. const lines = [`TAP version 13\n1..${results.length}`];
  8. for (const [index, result] of results.entries()) {
  9. preprocessWarnings(result);
  10. lines.push(
  11. `${result.errored ? 'not ok' : 'ok'} ${index + 1} - ${result.ignored ? 'ignored ' : ''}${
  12. result.source
  13. }`,
  14. );
  15. if (result.warnings.length > 0) {
  16. lines.push('---', 'messages:');
  17. for (const warning of result.warnings) {
  18. lines.push(
  19. ` - message: "${warning.text}"`,
  20. ` severity: ${warning.severity}`,
  21. ` data:`,
  22. ` line: ${warning.line}`,
  23. ` column: ${warning.column}`,
  24. );
  25. if (typeof warning.endLine === 'number') {
  26. lines.push(` endLine: ${warning.endLine}`);
  27. }
  28. if (typeof warning.endColumn === 'number') {
  29. lines.push(` endColumn: ${warning.endColumn}`);
  30. }
  31. if (typeof warning.rule === 'string') {
  32. lines.push(` ruleId: ${warning.rule}`);
  33. }
  34. }
  35. lines.push('---');
  36. }
  37. }
  38. lines.push('');
  39. return lines.join('\n');
  40. };