HumanReadableLogs.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* eslint-disable
  2. max-len,
  3. no-undef,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. define([
  15. 'libs/latex-log-parser',
  16. 'ide/human-readable-logs/HumanReadableLogsRules'
  17. ], (LogParser, ruleset) => ({
  18. parse(rawLog, options) {
  19. let parsedLogEntries
  20. if (typeof rawLog === 'string') {
  21. parsedLogEntries = LogParser.parse(rawLog, options)
  22. } else {
  23. parsedLogEntries = rawLog
  24. }
  25. const _getRule = function(logMessage) {
  26. for (let rule of Array.from(ruleset)) {
  27. if (rule.regexToMatch.test(logMessage)) {
  28. return rule
  29. }
  30. }
  31. }
  32. const seenErrorTypes = {} // keep track of types of errors seen
  33. for (let entry of Array.from(parsedLogEntries.all)) {
  34. const ruleDetails = _getRule(entry.message)
  35. if (ruleDetails != null) {
  36. var type
  37. if (ruleDetails.ruleId != null) {
  38. entry.ruleId = ruleDetails.ruleId
  39. } else if (ruleDetails.regexToMatch != null) {
  40. entry.ruleId = `hint_${ruleDetails.regexToMatch
  41. .toString()
  42. .replace(/\s/g, '_')
  43. .slice(1, -1)}`
  44. }
  45. if (ruleDetails.newMessage != null) {
  46. entry.message = entry.message.replace(
  47. ruleDetails.regexToMatch,
  48. ruleDetails.newMessage
  49. )
  50. }
  51. // suppress any entries that are known to cascade from previous error types
  52. if (ruleDetails.cascadesFrom != null) {
  53. for (type of Array.from(ruleDetails.cascadesFrom)) {
  54. if (seenErrorTypes[type]) {
  55. entry.suppressed = true
  56. }
  57. }
  58. }
  59. // record the types of errors seen
  60. if (ruleDetails.types != null) {
  61. for (type of Array.from(ruleDetails.types)) {
  62. seenErrorTypes[type] = true
  63. }
  64. }
  65. if (ruleDetails.humanReadableHint != null) {
  66. entry.humanReadableHint = ruleDetails.humanReadableHint
  67. }
  68. if (ruleDetails.extraInfoURL != null) {
  69. entry.extraInfoURL = ruleDetails.extraInfoURL
  70. }
  71. }
  72. }
  73. // filter out the suppressed errors (from the array entries in parsedLogEntries)
  74. for (let key in parsedLogEntries) {
  75. const errors = parsedLogEntries[key]
  76. if (typeof errors === 'object' && errors.length > 0) {
  77. parsedLogEntries[key] = Array.from(errors).filter(
  78. err => !err.suppressed
  79. )
  80. }
  81. }
  82. return parsedLogEntries
  83. }
  84. }))