unix.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @fileoverview unix-style formatter.
  3. * @author oshi-shinobu
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Helper Functions
  8. //------------------------------------------------------------------------------
  9. /**
  10. * Returns a canonical error level string based upon the error message passed in.
  11. * @param {Object} message Individual error message provided by eslint
  12. * @returns {string} Error level string
  13. */
  14. function getMessageType(message) {
  15. if (message.fatal || message.severity === 2) {
  16. return "Error";
  17. }
  18. return "Warning";
  19. }
  20. //------------------------------------------------------------------------------
  21. // Public Interface
  22. //------------------------------------------------------------------------------
  23. module.exports = function(results) {
  24. let output = "",
  25. total = 0;
  26. results.forEach(result => {
  27. const messages = result.messages;
  28. total += messages.length;
  29. messages.forEach(message => {
  30. output += `${result.filePath}:`;
  31. output += `${message.line || 0}:`;
  32. output += `${message.column || 0}:`;
  33. output += ` ${message.message} `;
  34. output += `[${getMessageType(message)}${message.ruleId ? `/${message.ruleId}` : ""}]`;
  35. output += "\n";
  36. });
  37. });
  38. if (total > 0) {
  39. output += `\n${total} problem${total !== 1 ? "s" : ""}`;
  40. }
  41. return output;
  42. };