EsLintIssueFactory.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. var Issue_1 = require("../Issue");
  15. var IssueOrigin_1 = require("../IssueOrigin");
  16. var IssueSeverity_1 = require("../IssueSeverity");
  17. function createIssueFromEsLintMessage(message) {
  18. return {
  19. origin: IssueOrigin_1.IssueOrigin.ESLINT,
  20. code: message.ruleId ? String(message.ruleId) : '[unknown]',
  21. severity: message.severity === 1 ? IssueSeverity_1.IssueSeverity.WARNING : IssueSeverity_1.IssueSeverity.ERROR,
  22. message: message.message,
  23. file: message.filePath,
  24. line: message.line,
  25. character: message.column
  26. };
  27. }
  28. function createFileAwareEsLintMessagesFromEsLintResult(result) {
  29. return result.messages.map(function (message) { return (__assign({}, message, { filePath: result.filePath })); });
  30. }
  31. function createFileAwareEsLintMessagesFromEsLintReport(report) {
  32. return report.results.reduce(function (messages, result) { return messages.concat(createFileAwareEsLintMessagesFromEsLintResult(result)); }, []);
  33. }
  34. function createFileAwareEsLintMessagesFromEsLintReports(reports) {
  35. return reports.reduce(function (messages, report) { return messages.concat(createFileAwareEsLintMessagesFromEsLintReport(report)); }, []);
  36. }
  37. function createIssuesFromEsLintMessages(messages) {
  38. return Issue_1.deduplicateAndSortIssues(messages.map(createIssueFromEsLintMessage));
  39. }
  40. function createIssuesFromEsLintReports(reports) {
  41. return createIssuesFromEsLintMessages(createFileAwareEsLintMessagesFromEsLintReports(reports));
  42. }
  43. exports.createIssuesFromEsLintReports = createIssuesFromEsLintReports;
  44. //# sourceMappingURL=EsLintIssueFactory.js.map