jslint-xml.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @fileoverview JSLint XML reporter
  3. * @author Ian Christian Myers
  4. */
  5. "use strict";
  6. const xmlEscape = require("../xml-escape");
  7. //------------------------------------------------------------------------------
  8. // Public Interface
  9. //------------------------------------------------------------------------------
  10. module.exports = function(results) {
  11. let output = "";
  12. output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
  13. output += "<jslint>";
  14. results.forEach(result => {
  15. const messages = result.messages;
  16. output += `<file name="${result.filePath}">`;
  17. messages.forEach(message => {
  18. output += [
  19. `<issue line="${message.line}"`,
  20. `char="${message.column}"`,
  21. `evidence="${xmlEscape(message.source || "")}"`,
  22. `reason="${xmlEscape(message.message || "")}${message.ruleId ? ` (${message.ruleId})` : ""}" />`
  23. ].join(" ");
  24. });
  25. output += "</file>";
  26. });
  27. output += "</jslint>";
  28. return output;
  29. };