HumanReadableLogsRules.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* eslint-disable no-useless-escape */
  2. import {
  3. packageSuggestionsForCommands,
  4. packageSuggestionsForEnvironments,
  5. } from './HumanReadableLogsPackageSuggestions'
  6. interface Rule {
  7. ruleId: string
  8. types?: string[]
  9. cascadesFrom?: string[]
  10. newMessage?: string
  11. regexToMatch: RegExp
  12. contentRegex?: RegExp
  13. improvedTitle?: (
  14. currentTitle: string,
  15. details?: [string]
  16. ) => string | [string, JSX.Element]
  17. }
  18. const rules: Rule[] = [
  19. {
  20. ruleId: 'hint_misplaced_alignment_tab_character',
  21. regexToMatch: /Misplaced alignment tab character \&/,
  22. },
  23. {
  24. ruleId: 'hint_extra_alignment_tab_has_been_changed',
  25. regexToMatch: /Extra alignment tab has been changed to \\cr/,
  26. },
  27. {
  28. ruleId: 'hint_display_math_should_end_with',
  29. regexToMatch: /Display math should end with \$\$/,
  30. },
  31. {
  32. ruleId: 'hint_missing_inserted',
  33. regexToMatch: /Missing [{$] inserted./,
  34. },
  35. {
  36. ruleId: 'hint_reference_undefined',
  37. regexToMatch: /Reference.+undefined/,
  38. },
  39. {
  40. ruleId: 'hint_there_were_undefined_references',
  41. regexToMatch: /There were undefined references/,
  42. },
  43. {
  44. ruleId: 'hint_citation_on_page_undefined_on_input_line',
  45. regexToMatch: /Citation .+ on page .+ undefined on input line .+/,
  46. },
  47. {
  48. ruleId: 'hint_label_multiply_defined_labels',
  49. regexToMatch: /(Label .+)? multiply[ -]defined( labels)?/,
  50. },
  51. {
  52. ruleId: 'hint_float_specifier_changed',
  53. regexToMatch: /`!?h' float specifier changed to `!?ht'/,
  54. },
  55. {
  56. ruleId: 'hint_no_positions_in_optional_float_specifier',
  57. regexToMatch: /No positions in optional float specifier/,
  58. },
  59. {
  60. ruleId: 'hint_undefined_control_sequence',
  61. regexToMatch: /Undefined control sequence/,
  62. // Match the last control sequence in the line
  63. contentRegex: /^[^\n]*(\\\S+)\s*[\n]/,
  64. improvedTitle: (currentTitle: string, details?: [string]) => {
  65. if (details?.length && packageSuggestionsForCommands.has(details[0])) {
  66. const command = details[0]
  67. const suggestion = packageSuggestionsForCommands.get(command)
  68. return [
  69. `Is ${suggestion.command} missing?`,
  70. // eslint-disable-next-line react/jsx-key
  71. <span>
  72. Is <code>{suggestion.command}</code> missing?
  73. </span>,
  74. ]
  75. }
  76. return currentTitle
  77. },
  78. },
  79. {
  80. ruleId: 'hint_undefined_environment',
  81. regexToMatch: /LaTeX Error: Environment .+ undefined/,
  82. contentRegex: /\\begin\{(\S+)\}/,
  83. improvedTitle: (currentTitle: string, details?: [string]) => {
  84. if (
  85. details?.length &&
  86. packageSuggestionsForEnvironments.has(details[0])
  87. ) {
  88. const environment = details[0]
  89. const suggestion = packageSuggestionsForEnvironments.get(environment)
  90. return [
  91. `Is ${suggestion.command} missing?`,
  92. // eslint-disable-next-line react/jsx-key
  93. <span>
  94. Is <code>{suggestion.command}</code> missing?
  95. </span>,
  96. ]
  97. }
  98. return currentTitle
  99. },
  100. },
  101. {
  102. ruleId: 'hint_file_not_found',
  103. regexToMatch: /File .+ not found/,
  104. },
  105. {
  106. ruleId: 'hint_unknown_graphics_extension',
  107. regexToMatch: /LaTeX Error: Unknown graphics extension: \..+/,
  108. },
  109. {
  110. ruleId: 'hint_unknown_float_option_h',
  111. regexToMatch: /LaTeX Error: Unknown float option `H'/,
  112. },
  113. {
  114. ruleId: 'hint_unknown_float_option_q',
  115. regexToMatch: /LaTeX Error: Unknown float option `q'/,
  116. },
  117. {
  118. ruleId: 'hint_math_allowed_only_in_math_mode',
  119. regexToMatch: /LaTeX Error: \\math.+ allowed only in math mode/,
  120. },
  121. {
  122. ruleId: 'hint_mismatched_environment',
  123. types: ['environment'],
  124. regexToMatch: /Error: `([^']{2,})' expected, found `([^']{2,})'.*/,
  125. newMessage: 'Error: environment does not match \\begin{$1} ... \\end{$2}',
  126. },
  127. {
  128. ruleId: 'hint_mismatched_brackets',
  129. types: ['environment'],
  130. regexToMatch: /Error: `([^a-zA-Z0-9])' expected, found `([^a-zA-Z0-9])'.*/,
  131. newMessage: "Error: brackets do not match, found '$2' instead of '$1'",
  132. },
  133. {
  134. ruleId: 'hint_can_be_used_only_in_preamble',
  135. regexToMatch: /LaTeX Error: Can be used only in preamble/,
  136. },
  137. {
  138. ruleId: 'hint_missing_right_inserted',
  139. regexToMatch: /Missing \\right inserted/,
  140. },
  141. {
  142. ruleId: 'hint_double_superscript',
  143. regexToMatch: /Double superscript/,
  144. },
  145. {
  146. ruleId: 'hint_double_subscript',
  147. regexToMatch: /Double subscript/,
  148. },
  149. {
  150. ruleId: 'hint_no_author_given',
  151. regexToMatch: /No \\author given/,
  152. },
  153. {
  154. ruleId: 'hint_somethings_wrong_perhaps_a_missing_item',
  155. regexToMatch: /LaTeX Error: Something's wrong--perhaps a missing \\item/,
  156. },
  157. {
  158. ruleId: 'hint_misplaced_noalign',
  159. regexToMatch: /Misplaced \\noalign/,
  160. },
  161. {
  162. ruleId: 'hint_no_line_here_to_end',
  163. regexToMatch: /LaTeX Error: There's no line here to end/,
  164. },
  165. {
  166. ruleId: 'hint_verb_ended_by_end_of_line',
  167. regexToMatch: /LaTeX Error: \\verb ended by end of line/,
  168. },
  169. {
  170. ruleId: 'hint_illegal_unit_of_measure_pt_inserted',
  171. regexToMatch: /Illegal unit of measure (pt inserted)/,
  172. },
  173. {
  174. ruleId: 'hint_extra_right',
  175. regexToMatch: /Extra \\right/,
  176. },
  177. {
  178. ruleId: 'hint_missing_begin_document_',
  179. regexToMatch: /Missing \\begin{document}/,
  180. },
  181. {
  182. ruleId: 'hint_mismatched_environment2',
  183. types: ['environment'],
  184. cascadesFrom: ['environment'],
  185. regexToMatch:
  186. /Error: `\\end\{([^\}]+)\}' expected but found `\\end\{([^\}]+)\}'.*/,
  187. newMessage: 'Error: environments do not match: \\begin{$1} ... \\end{$2}',
  188. },
  189. {
  190. ruleId: 'hint_mismatched_environment3',
  191. types: ['environment'],
  192. cascadesFrom: ['environment'],
  193. regexToMatch:
  194. /Warning: No matching \\end found for `\\begin\{([^\}]+)\}'.*/,
  195. newMessage: 'Warning: No matching \\end found for \\begin{$1}',
  196. },
  197. {
  198. ruleId: 'hint_mismatched_environment4',
  199. types: ['environment'],
  200. cascadesFrom: ['environment'],
  201. regexToMatch:
  202. /Error: Found `\\end\{([^\}]+)\}' without corresponding \\begin.*/,
  203. newMessage: 'Error: found \\end{$1} without a corresponding \\begin{$1}',
  204. },
  205. ]
  206. export default rules