Issue.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var IssueSeverity_1 = require("./IssueSeverity");
  4. var IssueOrigin_1 = require("./IssueOrigin");
  5. function isIssue(value) {
  6. return (!!value &&
  7. typeof value === 'object' &&
  8. IssueOrigin_1.isIssueOrigin(value.origin) &&
  9. IssueSeverity_1.isIssueSeverity(value.severity) &&
  10. !!value.code &&
  11. !!value.message);
  12. }
  13. exports.isIssue = isIssue;
  14. function compareOptionalStrings(stringA, stringB) {
  15. if (stringA === stringB) {
  16. return 0;
  17. }
  18. if (stringA === undefined || stringA === null) {
  19. return -1;
  20. }
  21. if (stringB === undefined || stringB === null) {
  22. return 1;
  23. }
  24. return stringA.toString().localeCompare(stringB.toString());
  25. }
  26. function compareNumbers(numberA, numberB) {
  27. if (numberA === numberB) {
  28. return 0;
  29. }
  30. if (numberA === undefined || numberA === null) {
  31. return -1;
  32. }
  33. if (numberB === undefined || numberB === null) {
  34. return 1;
  35. }
  36. return Math.sign(numberA - numberB);
  37. }
  38. function compareIssues(issueA, issueB) {
  39. return (IssueOrigin_1.compareIssueOrigins(issueA.origin, issueB.origin) ||
  40. compareOptionalStrings(issueA.file, issueB.file) ||
  41. IssueSeverity_1.compareIssueSeverities(issueA.severity, issueB.severity) ||
  42. compareNumbers(issueA.line, issueB.line) ||
  43. compareNumbers(issueA.character, issueB.character) ||
  44. compareOptionalStrings(issueA.code, issueB.code) ||
  45. compareOptionalStrings(issueA.message, issueB.message) ||
  46. compareOptionalStrings(issueA.stack, issueB.stack) ||
  47. 0 /* EqualTo */);
  48. }
  49. function equalsIssues(issueA, issueB) {
  50. return compareIssues(issueA, issueB) === 0;
  51. }
  52. function deduplicateAndSortIssues(issues) {
  53. var sortedIssues = issues.filter(isIssue).sort(compareIssues);
  54. return sortedIssues.filter(function (issue, index) {
  55. return index === 0 || !equalsIssues(issue, sortedIssues[index - 1]);
  56. });
  57. }
  58. exports.deduplicateAndSortIssues = deduplicateAndSortIssues;
  59. //# sourceMappingURL=Issue.js.map