You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

4 years ago
  1. /**
  2. * @fileoverview Visual Studio compatible formatter
  3. * @author Ronald Pijnacker
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Helper Functions
  8. //------------------------------------------------------------------------------
  9. /**
  10. * Returns the severity of warning or error
  11. * @param {Object} message message object to examine
  12. * @returns {string} severity level
  13. * @private
  14. */
  15. function getMessageType(message) {
  16. if (message.fatal || message.severity === 2) {
  17. return "error";
  18. }
  19. return "warning";
  20. }
  21. //------------------------------------------------------------------------------
  22. // Public Interface
  23. //------------------------------------------------------------------------------
  24. module.exports = function(results) {
  25. let output = "",
  26. total = 0;
  27. results.forEach(result => {
  28. const messages = result.messages;
  29. total += messages.length;
  30. messages.forEach(message => {
  31. output += result.filePath;
  32. output += `(${message.line || 0}`;
  33. output += message.column ? `,${message.column}` : "";
  34. output += `): ${getMessageType(message)}`;
  35. output += message.ruleId ? ` ${message.ruleId}` : "";
  36. output += ` : ${message.message}`;
  37. output += "\n";
  38. });
  39. });
  40. if (total === 0) {
  41. output += "no problems";
  42. } else {
  43. output += `\n${total} problem${total !== 1 ? "s" : ""}`;
  44. }
  45. return output;
  46. };