@alexlit/lint-kit 107.2.2 → 108.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/.eslintrc.cjs +9 -0
  2. package/.linthtmlrc.cjs +5 -0
  3. package/{.commitlintrc.js → commitlint.config.js} +1 -1
  4. package/package.json +11 -10
  5. package/packages/config-commitlint/LICENSE +20 -0
  6. package/packages/config-commitlint/README.md +5 -9
  7. package/packages/config-commitlint/index.js +1 -1
  8. package/packages/config-commitlint/package.json +4 -3
  9. package/packages/config-eslint/LICENSE +20 -0
  10. package/packages/config-eslint/dictionaries/index.js +2 -1
  11. package/packages/config-eslint/index.js +14 -3
  12. package/packages/config-eslint/package.json +25 -25
  13. package/packages/config-eslint/plugins/typescript/index.js +1 -1
  14. package/packages/config-eslint/plugins/unicorn.js +2 -0
  15. package/packages/config-eslint/plugins/vue.js +34 -2
  16. package/packages/config-hooks/LICENSE +20 -0
  17. package/packages/config-hooks/README.md +18 -12
  18. package/packages/config-hooks/index.js +2 -0
  19. package/packages/config-hooks/lint-staged.js +4 -4
  20. package/packages/config-hooks/package.json +6 -5
  21. package/packages/config-htmllint/LICENSE +20 -0
  22. package/packages/config-markdownlint/LICENSE +20 -0
  23. package/packages/config-markdownlint/README.md +5 -5
  24. package/packages/config-markdownlint/index.json +17 -0
  25. package/packages/config-markdownlint/package.json +5 -5
  26. package/packages/config-npmlint/LICENSE +20 -0
  27. package/packages/config-npmlint/package.json +2 -2
  28. package/packages/config-prettier/LICENSE +20 -0
  29. package/packages/config-prettier/README.md +8 -3
  30. package/packages/config-prettier/index.js +14 -10
  31. package/packages/config-prettier/package.json +16 -12
  32. package/packages/config-prettier/plugins/jsdoc.js +1 -1
  33. package/packages/config-prettier/plugins/pug.js +1 -1
  34. package/packages/config-prettier/plugins/sort-json.js +1 -1
  35. package/packages/config-prettier/plugins/svelte.js +1 -1
  36. package/packages/config-prettier/plugins/tailwindcss.js +1 -1
  37. package/packages/config-prettier/plugins/xml.js +1 -1
  38. package/packages/config-stylelint/LICENSE +20 -0
  39. package/packages/config-stylelint/README.md +5 -4
  40. package/packages/config-stylelint/index.js +22 -25
  41. package/packages/config-stylelint/package.json +22 -18
  42. package/packages/config-stylelint/plugins/a11y.js +1 -1
  43. package/packages/config-stylelint/plugins/at-rule-no-children.js +1 -1
  44. package/packages/config-stylelint/plugins/color-format.js +1 -1
  45. package/packages/config-stylelint/plugins/declaration-block-no-ignored-properties.js +1 -1
  46. package/packages/config-stylelint/plugins/high-performance-animation.js +1 -1
  47. package/packages/config-stylelint/plugins/no-nested-media.js +1 -1
  48. package/packages/config-stylelint/plugins/no-unresolved-module.js +1 -1
  49. package/packages/config-stylelint/plugins/no-unsupported-browser-features.js +1 -1
  50. package/packages/config-stylelint/plugins/optional/gamut.js +1 -1
  51. package/packages/config-stylelint/plugins/optional/logical-css.js +1 -1
  52. package/packages/config-stylelint/plugins/optional/no-indistinguishable-colors.js +1 -1
  53. package/packages/config-stylelint/plugins/order.js +1 -1
  54. package/packages/config-stylelint/plugins/prettier.js +1 -1
  55. package/packages/config-stylelint/plugins/scss.js +1 -1
  56. package/packages/config-stylelint/plugins/selector-no-empty.js +1 -1
  57. package/packages/config-stylelint/plugins/use-nesting.js +1 -1
  58. package/packages/config-stylelint/plugins/vue.js +1 -1
  59. package/prettier.config.js +5 -0
  60. package/scripts/lint.eslint.sh +1 -1
  61. package/scripts/lint.markdownlint.sh +1 -1
  62. package/stylelint.config.js +14 -0
  63. package/.eslintrc.js +0 -3
  64. package/.huskyrc.js +0 -3
  65. package/.linthtmlrc.js +0 -3
  66. package/.lintstagedrc.js +0 -3
  67. package/.markdownlintrc.js +0 -3
  68. package/.prettierrc.js +0 -3
  69. package/.stylelintrc.js +0 -4
  70. package/packages/config-hooks/husky.js +0 -6
  71. package/packages/config-markdownlint/index.js +0 -17
  72. package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +0 -22
  73. package/packages/config-markdownlint/node_modules/markdown-it/README.md +0 -309
  74. package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +0 -117
  75. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +0 -8441
  76. package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +0 -3
  77. package/packages/config-markdownlint/node_modules/markdown-it/index.js +0 -4
  78. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +0 -6
  79. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +0 -70
  80. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +0 -28
  81. package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +0 -317
  82. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +0 -7
  83. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +0 -80
  84. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +0 -48
  85. package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +0 -55
  86. package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +0 -582
  87. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +0 -131
  88. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +0 -61
  89. package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +0 -192
  90. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +0 -81
  91. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +0 -41
  92. package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +0 -63
  93. package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +0 -341
  94. package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +0 -352
  95. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +0 -226
  96. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +0 -34
  97. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +0 -98
  98. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +0 -55
  99. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +0 -45
  100. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +0 -74
  101. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +0 -83
  102. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +0 -362
  103. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +0 -51
  104. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +0 -198
  105. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +0 -231
  106. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +0 -221
  107. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +0 -16
  108. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +0 -13
  109. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +0 -142
  110. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +0 -21
  111. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +0 -105
  112. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +0 -201
  113. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +0 -20
  114. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +0 -45
  115. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +0 -76
  116. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +0 -63
  117. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +0 -130
  118. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +0 -130
  119. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +0 -55
  120. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +0 -71
  121. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +0 -41
  122. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +0 -58
  123. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +0 -152
  124. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +0 -150
  125. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +0 -62
  126. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +0 -46
  127. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +0 -158
  128. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +0 -130
  129. package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +0 -89
  130. package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +0 -201
  131. package/packages/config-markdownlint/node_modules/markdown-it/package.json +0 -87
  132. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +0 -428
  133. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +0 -92
  134. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +0 -21
  135. package/packages/config-markdownlint/node_modules/markdownlint/README.md +0 -1026
  136. package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +0 -6814
  137. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +0 -376
  138. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +0 -27
  139. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +0 -20
  140. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +0 -2335
  141. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +0 -37
  142. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +0 -59
  143. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +0 -49
  144. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +0 -53
  145. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +0 -52
  146. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +0 -51
  147. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +0 -56
  148. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +0 -30
  149. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +0 -38
  150. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +0 -57
  151. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +0 -54
  152. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +0 -27
  153. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +0 -28
  154. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +0 -29
  155. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +0 -31
  156. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +0 -52
  157. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +0 -33
  158. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +0 -47
  159. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +0 -49
  160. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +0 -40
  161. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +0 -24
  162. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +0 -40
  163. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +0 -98
  164. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +0 -82
  165. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +0 -50
  166. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +0 -55
  167. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +0 -27
  168. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +0 -50
  169. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +0 -42
  170. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +0 -45
  171. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +0 -37
  172. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +0 -40
  173. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +0 -21
  174. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +0 -52
  175. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +0 -49
  176. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +0 -32
  177. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +0 -69
  178. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +0 -35
  179. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +0 -40
  180. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +0 -40
  181. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +0 -34
  182. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +0 -41
  183. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +0 -32
  184. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +0 -32
  185. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +0 -61
  186. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +0 -40
  187. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +0 -38
  188. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +0 -100
  189. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +0 -21
  190. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +0 -70
  191. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +0 -1025
  192. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +0 -426
  193. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +0 -26
  194. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +0 -10
  195. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +0 -21
  196. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +0 -1152
  197. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +0 -14
  198. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +0 -406
  199. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +0 -1476
  200. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +0 -22
  201. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +0 -42
  202. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +0 -76
  203. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +0 -73
  204. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +0 -86
  205. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +0 -86
  206. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +0 -60
  207. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +0 -46
  208. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +0 -32
  209. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +0 -96
  210. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +0 -53
  211. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +0 -34
  212. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +0 -39
  213. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +0 -62
  214. package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +0 -62
  215. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +0 -108
  216. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +0 -38
  217. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +0 -38
  218. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +0 -32
  219. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +0 -50
  220. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +0 -56
  221. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +0 -30
  222. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +0 -67
  223. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +0 -61
  224. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +0 -40
  225. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +0 -78
  226. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +0 -39
  227. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +0 -79
  228. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +0 -24
  229. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +0 -56
  230. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +0 -91
  231. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +0 -97
  232. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +0 -67
  233. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +0 -37
  234. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +0 -42
  235. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +0 -49
  236. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +0 -64
  237. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +0 -107
  238. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +0 -60
  239. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +0 -33
  240. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +0 -28
  241. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +0 -30
  242. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +0 -89
  243. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +0 -172
  244. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +0 -39
  245. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +0 -59
  246. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +0 -125
  247. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +0 -65
  248. package/packages/config-markdownlint/node_modules/markdownlint/package.json +0 -109
  249. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +0 -297
  250. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +0 -266
  251. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +0 -1762
  252. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +0 -5
  253. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +0 -22
  254. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +0 -26
  255. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +0 -12
  256. /package/packages/config-eslint/plugins/{security.js → optional/security.js} +0 -0
@@ -1,1025 +0,0 @@
1
- // @ts-check
2
-
3
- "use strict";
4
-
5
- const micromark = require("./micromark.cjs");
6
-
7
- const { newLineRe, nextLinesRe } = require("./shared.js");
8
-
9
- module.exports.newLineRe = newLineRe;
10
- module.exports.nextLinesRe = nextLinesRe;
11
-
12
- // Regular expression for matching common front matter (YAML and TOML)
13
- module.exports.frontMatterRe =
14
- /((^---\s*$[\s\S]+?^---\s*)|(^\+\+\+\s*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
15
-
16
- // Regular expression for matching the start of inline disable/enable comments
17
- const inlineCommentStartRe =
18
- /(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
19
- module.exports.inlineCommentStartRe = inlineCommentStartRe;
20
-
21
- // Regular expressions for range matching
22
- module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
23
- module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
24
-
25
- // Regular expression for blockquote prefixes
26
- const blockquotePrefixRe = /^[>\s]*/;
27
- module.exports.blockquotePrefixRe = blockquotePrefixRe;
28
-
29
- // Regular expression for link reference definitions
30
- const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
31
- module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;
32
-
33
- // Regular expression for identifying an HTML entity at the end of a line
34
- module.exports.endOfLineHtmlEntityRe =
35
- /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
36
-
37
- // Regular expression for identifying a GitHub emoji code at the end of a line
38
- module.exports.endOfLineGemojiCodeRe =
39
- /:(?:[abmovx]|[-+]1|100|1234|(?:1st|2nd|3rd)_place_medal|8ball|clock\d{1,4}|e-mail|non-potable_water|o2|t-rex|u5272|u5408|u55b6|u6307|u6708|u6709|u6e80|u7121|u7533|u7981|u7a7a|[a-z]{2,15}2?|[a-z]{1,14}(?:_[a-z\d]{1,16})+):$/;
40
-
41
- // All punctuation characters (normal and full-width)
42
- const allPunctuation = ".,;:!?。,;:!?";
43
- module.exports.allPunctuation = allPunctuation;
44
-
45
- // All punctuation characters without question mark (normal and full-width)
46
- module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[??]/gu, "");
47
-
48
- /**
49
- * Returns true iff the input is a Number.
50
- *
51
- * @param {Object} obj Object of unknown type.
52
- * @returns {boolean} True iff obj is a Number.
53
- */
54
- function isNumber(obj) {
55
- return typeof obj === "number";
56
- }
57
- module.exports.isNumber = isNumber;
58
-
59
- /**
60
- * Returns true iff the input is a String.
61
- *
62
- * @param {Object} obj Object of unknown type.
63
- * @returns {boolean} True iff obj is a String.
64
- */
65
- function isString(obj) {
66
- return typeof obj === "string";
67
- }
68
- module.exports.isString = isString;
69
-
70
- /**
71
- * Returns true iff the input String is empty.
72
- *
73
- * @param {string} str String of unknown length.
74
- * @returns {boolean} True iff the input String is empty.
75
- */
76
- function isEmptyString(str) {
77
- return str.length === 0;
78
- }
79
- module.exports.isEmptyString = isEmptyString;
80
-
81
- /**
82
- * Returns true iff the input is an Object.
83
- *
84
- * @param {Object} obj Object of unknown type.
85
- * @returns {boolean} True iff obj is an Object.
86
- */
87
- function isObject(obj) {
88
- return !!obj && (typeof obj === "object") && !Array.isArray(obj);
89
- }
90
- module.exports.isObject = isObject;
91
-
92
- /**
93
- * Returns true iff the input is a URL.
94
- *
95
- * @param {Object} obj Object of unknown type.
96
- * @returns {boolean} True iff obj is a URL.
97
- */
98
- function isUrl(obj) {
99
- return !!obj && (Object.getPrototypeOf(obj) === URL.prototype);
100
- }
101
- module.exports.isUrl = isUrl;
102
-
103
- /**
104
- * Clones the input if it is an Array.
105
- *
106
- * @param {Object} arr Object of unknown type.
107
- * @returns {Object} Clone of obj iff obj is an Array.
108
- */
109
- function cloneIfArray(arr) {
110
- return Array.isArray(arr) ? [ ...arr ] : arr;
111
- }
112
- module.exports.cloneIfArray = cloneIfArray;
113
-
114
- /**
115
- * Clones the input if it is a URL.
116
- *
117
- * @param {Object} url Object of unknown type.
118
- * @returns {Object} Clone of obj iff obj is a URL.
119
- */
120
- function cloneIfUrl(url) {
121
- return isUrl(url) ? new URL(url) : url;
122
- }
123
- module.exports.cloneIfUrl = cloneIfUrl;
124
-
125
- /**
126
- * Gets a Regular Expression for matching the specified HTML attribute.
127
- *
128
- * @param {string} name HTML attribute name.
129
- * @returns {RegExp} Regular Expression for matching.
130
- */
131
- module.exports.getHtmlAttributeRe = function getHtmlAttributeRe(name) {
132
- return new RegExp(`\\s${name}\\s*=\\s*['"]?([^'"\\s>]*)`, "iu");
133
- };
134
-
135
- /**
136
- * Returns true iff the input line is blank (contains nothing, whitespace, or
137
- * comments (unclosed start/end comments allowed)).
138
- *
139
- * @param {string} line Input line.
140
- * @returns {boolean} True iff line is blank.
141
- */
142
- function isBlankLine(line) {
143
- const startComment = "<!--";
144
- const endComment = "-->";
145
- const removeComments = (s) => {
146
- // eslint-disable-next-line no-constant-condition
147
- while (true) {
148
- const start = s.indexOf(startComment);
149
- const end = s.indexOf(endComment);
150
- if ((end !== -1) && ((start === -1) || (end < start))) {
151
- // Unmatched end comment is first
152
- s = s.slice(end + endComment.length);
153
- } else if ((start !== -1) && (end !== -1)) {
154
- // Start comment is before end comment
155
- s = s.slice(0, start) + s.slice(end + endComment.length);
156
- } else if ((start !== -1) && (end === -1)) {
157
- // Unmatched start comment is last
158
- s = s.slice(0, start);
159
- } else {
160
- // No more comments to remove
161
- return s;
162
- }
163
- }
164
- };
165
- return (
166
- !line ||
167
- !line.trim() ||
168
- !removeComments(line).replace(/>/g, "").trim()
169
- );
170
- }
171
- module.exports.isBlankLine = isBlankLine;
172
-
173
- /**
174
- * Compare function for Array.prototype.sort for ascending order of numbers.
175
- *
176
- * @param {number} a First number.
177
- * @param {number} b Second number.
178
- * @returns {number} Positive value if a>b, negative value if b<a, 0 otherwise.
179
- */
180
- module.exports.numericSortAscending = function numericSortAscending(a, b) {
181
- return a - b;
182
- };
183
-
184
- // Returns true iff the sorted array contains the specified element
185
- module.exports.includesSorted = function includesSorted(array, element) {
186
- let left = 0;
187
- let right = array.length - 1;
188
- while (left <= right) {
189
- // eslint-disable-next-line no-bitwise
190
- const mid = (left + right) >> 1;
191
- if (array[mid] < element) {
192
- left = mid + 1;
193
- } else if (array[mid] > element) {
194
- right = mid - 1;
195
- } else {
196
- return true;
197
- }
198
- }
199
- return false;
200
- };
201
-
202
- // Replaces the content of properly-formatted CommonMark comments with "."
203
- // This preserves the line/column information for the rest of the document
204
- // https://spec.commonmark.org/0.29/#html-blocks
205
- // https://spec.commonmark.org/0.29/#html-comment
206
- const htmlCommentBegin = "<!--";
207
- const htmlCommentEnd = "-->";
208
- const safeCommentCharacter = ".";
209
- const startsWithPipeRe = /^ *\|/;
210
- const notCrLfRe = /[^\r\n]/g;
211
- const notSpaceCrLfRe = /[^ \r\n]/g;
212
- const trailingSpaceRe = / +[\r\n]/g;
213
- const replaceTrailingSpace = (s) => s.replace(notCrLfRe, safeCommentCharacter);
214
- module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
215
- let i = 0;
216
- while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) {
217
- const j = text.indexOf(htmlCommentEnd, i + 2);
218
- if (j === -1) {
219
- // Un-terminated comments are treated as text
220
- break;
221
- }
222
- // If the comment has content...
223
- if (j > i + htmlCommentBegin.length) {
224
- const content = text.slice(i + htmlCommentBegin.length, j);
225
- const lastLf = text.lastIndexOf("\n", i) + 1;
226
- const preText = text.slice(lastLf, i);
227
- const isBlock = preText.trim().length === 0;
228
- const couldBeTable = startsWithPipeRe.test(preText);
229
- const spansTableCells = couldBeTable && content.includes("\n");
230
- const isValid =
231
- isBlock ||
232
- !(
233
- spansTableCells ||
234
- content.startsWith(">") ||
235
- content.startsWith("->") ||
236
- content.endsWith("-") ||
237
- content.includes("--")
238
- );
239
- // If a valid block/inline comment...
240
- if (isValid) {
241
- const clearedContent = content
242
- .replace(notSpaceCrLfRe, safeCommentCharacter)
243
- .replace(trailingSpaceRe, replaceTrailingSpace);
244
- text =
245
- text.slice(0, i + htmlCommentBegin.length) +
246
- clearedContent +
247
- text.slice(j);
248
- }
249
- }
250
- i = j + htmlCommentEnd.length;
251
- }
252
- return text;
253
- };
254
-
255
- // Escapes a string for use in a RegExp
256
- module.exports.escapeForRegExp = function escapeForRegExp(str) {
257
- return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
258
- };
259
-
260
- /**
261
- * Return the string representation of a fence markup character.
262
- *
263
- * @param {string} markup Fence string.
264
- * @returns {string} String representation.
265
- */
266
- module.exports.fencedCodeBlockStyleFor =
267
- function fencedCodeBlockStyleFor(markup) {
268
- switch (markup[0]) {
269
- case "~":
270
- return "tilde";
271
- default:
272
- return "backtick";
273
- }
274
- };
275
-
276
- /**
277
- * Return the string representation of a emphasis or strong markup character.
278
- *
279
- * @param {string} markup Emphasis or strong string.
280
- * @returns {string} String representation.
281
- */
282
- module.exports.emphasisOrStrongStyleFor =
283
- function emphasisOrStrongStyleFor(markup) {
284
- switch (markup[0]) {
285
- case "*":
286
- return "asterisk";
287
- default:
288
- return "underscore";
289
- }
290
- };
291
-
292
- /**
293
- * Return the number of characters of indent for a token.
294
- *
295
- * @param {Object} token MarkdownItToken instance.
296
- * @returns {number} Characters of indent.
297
- */
298
- function indentFor(token) {
299
- const line = token.line.replace(/^[\s>]*(> |>)/, "");
300
- return line.length - line.trimStart().length;
301
- }
302
- module.exports.indentFor = indentFor;
303
-
304
- // Returns the heading style for a heading token
305
- module.exports.headingStyleFor = function headingStyleFor(token) {
306
- if ((token.map[1] - token.map[0]) === 1) {
307
- if (/[^\\]#\s*$/.test(token.line)) {
308
- return "atx_closed";
309
- }
310
- return "atx";
311
- }
312
- return "setext";
313
- };
314
-
315
- /**
316
- * Return the string representation of an unordered list marker.
317
- *
318
- * @param {Object} token MarkdownItToken instance.
319
- * @returns {string} String representation.
320
- */
321
- module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) {
322
- switch (token.markup) {
323
- case "-":
324
- return "dash";
325
- case "+":
326
- return "plus";
327
- // case "*":
328
- default:
329
- return "asterisk";
330
- }
331
- };
332
-
333
- /**
334
- * @callback TokenCallback
335
- * @param {MarkdownItToken} token Current token.
336
- * @returns {void}
337
- */
338
-
339
- /**
340
- * Calls the provided function for each matching token.
341
- *
342
- * @param {Object} params RuleParams instance.
343
- * @param {string} type Token type identifier.
344
- * @param {TokenCallback} handler Callback function.
345
- * @returns {void}
346
- */
347
- function filterTokens(params, type, handler) {
348
- for (const token of params.parsers.markdownit.tokens) {
349
- if (token.type === type) {
350
- handler(token);
351
- }
352
- }
353
- }
354
- module.exports.filterTokens = filterTokens;
355
-
356
- /**
357
- * @typedef {Array} LineMetadata
358
- */
359
-
360
- /**
361
- * Gets a line metadata array.
362
- *
363
- * @param {Object} params RuleParams instance.
364
- * @returns {LineMetadata} Line metadata.
365
- */
366
- function getLineMetadata(params) {
367
- const lineMetadata = params.lines.map(
368
- (line, index) => [ line, index, false, 0, false, false, false ]
369
- );
370
- filterTokens(params, "fence", (token) => {
371
- lineMetadata[token.map[0]][3] = 1;
372
- lineMetadata[token.map[1] - 1][3] = -1;
373
- for (let i = token.map[0] + 1; i < token.map[1] - 1; i++) {
374
- lineMetadata[i][2] = true;
375
- }
376
- });
377
- filterTokens(params, "code_block", (token) => {
378
- for (let i = token.map[0]; i < token.map[1]; i++) {
379
- lineMetadata[i][2] = true;
380
- }
381
- });
382
- filterTokens(params, "table_open", (token) => {
383
- for (let i = token.map[0]; i < token.map[1]; i++) {
384
- lineMetadata[i][4] = true;
385
- }
386
- });
387
- filterTokens(params, "list_item_open", (token) => {
388
- let count = 1;
389
- for (let i = token.map[0]; i < token.map[1]; i++) {
390
- lineMetadata[i][5] = count;
391
- count++;
392
- }
393
- });
394
- filterTokens(params, "hr", (token) => {
395
- lineMetadata[token.map[0]][6] = true;
396
- });
397
- return lineMetadata;
398
- }
399
- module.exports.getLineMetadata = getLineMetadata;
400
-
401
- /**
402
- * @callback EachLineCallback
403
- * @param {string} line Line content.
404
- * @param {number} lineIndex Line index (0-based).
405
- * @param {boolean} inCode Iff in a code block.
406
- * @param {number} onFence + if open, - if closed, 0 otherwise.
407
- * @param {boolean} inTable Iff in a table.
408
- * @param {boolean} inItem Iff in a list item.
409
- * @param {boolean} inBreak Iff in semantic break.
410
- * @returns {void}
411
- */
412
-
413
- /**
414
- * Calls the provided function for each line.
415
- *
416
- * @param {LineMetadata} lineMetadata Line metadata object.
417
- * @param {EachLineCallback} handler Function taking (line, lineIndex, inCode,
418
- * onFence, inTable, inItem, inBreak).
419
- * @returns {void}
420
- */
421
- function forEachLine(lineMetadata, handler) {
422
- for (const metadata of lineMetadata) {
423
- // @ts-ignore
424
- handler(...metadata);
425
- }
426
- }
427
- module.exports.forEachLine = forEachLine;
428
-
429
- // Returns (nested) lists as a flat array (in order)
430
- module.exports.flattenLists = function flattenLists(tokens) {
431
- const flattenedLists = [];
432
- const stack = [];
433
- let current = null;
434
- let nesting = 0;
435
- const nestingStack = [];
436
- let lastWithMap = { "map": [ 0, 1 ] };
437
- for (const token of tokens) {
438
- if ((token.type === "bullet_list_open") ||
439
- (token.type === "ordered_list_open")) {
440
- // Save current context and start a new one
441
- stack.push(current);
442
- current = {
443
- "unordered": (token.type === "bullet_list_open"),
444
- "parentsUnordered": !current ||
445
- (current.unordered && current.parentsUnordered),
446
- "open": token,
447
- "indent": indentFor(token),
448
- "parentIndent": (current && current.indent) || 0,
449
- "items": [],
450
- "nesting": nesting,
451
- "lastLineIndex": -1,
452
- "insert": flattenedLists.length
453
- };
454
- nesting++;
455
- } else if ((token.type === "bullet_list_close") ||
456
- (token.type === "ordered_list_close")) {
457
- // Finalize current context and restore previous
458
- current.lastLineIndex = lastWithMap.map[1];
459
- flattenedLists.splice(current.insert, 0, current);
460
- delete current.insert;
461
- current = stack.pop();
462
- nesting--;
463
- } else if (token.type === "list_item_open") {
464
- // Add list item
465
- current.items.push(token);
466
- } else if (token.type === "blockquote_open") {
467
- nestingStack.push(nesting);
468
- nesting = 0;
469
- } else if (token.type === "blockquote_close") {
470
- nesting = nestingStack.pop() || 0;
471
- }
472
- if (token.map) {
473
- // Track last token with map
474
- lastWithMap = token;
475
- }
476
- }
477
- return flattenedLists;
478
- };
479
-
480
- // Calls the provided function for each heading's content
481
- module.exports.forEachHeading = function forEachHeading(params, handler) {
482
- let heading = null;
483
- for (const token of params.parsers.markdownit.tokens) {
484
- if (token.type === "heading_open") {
485
- heading = token;
486
- } else if (token.type === "heading_close") {
487
- heading = null;
488
- } else if ((token.type === "inline") && heading) {
489
- handler(heading, token.content, token);
490
- }
491
- }
492
- };
493
-
494
- /**
495
- * @callback InlineCodeSpanCallback
496
- * @param {string} code Code content.
497
- * @param {number} lineIndex Line index (0-based).
498
- * @param {number} columnIndex Column index (0-based).
499
- * @param {number} ticks Count of backticks.
500
- * @returns {void}
501
- */
502
-
503
- /**
504
- * Calls the provided function for each inline code span's content.
505
- *
506
- * @param {string} input Markdown content.
507
- * @param {InlineCodeSpanCallback} handler Callback function taking (code,
508
- * lineIndex, columnIndex, ticks).
509
- * @returns {void}
510
- */
511
- function forEachInlineCodeSpan(input, handler) {
512
- const backtickRe = /`+/g;
513
- let match = null;
514
- const backticksLengthAndIndex = [];
515
- while ((match = backtickRe.exec(input)) !== null) {
516
- backticksLengthAndIndex.push([ match[0].length, match.index ]);
517
- }
518
- const newLinesIndex = [];
519
- while ((match = newLineRe.exec(input)) !== null) {
520
- newLinesIndex.push(match.index);
521
- }
522
- let lineIndex = 0;
523
- let lineStartIndex = 0;
524
- let k = 0;
525
- for (let i = 0; i < backticksLengthAndIndex.length - 1; i++) {
526
- const [ startLength, startIndex ] = backticksLengthAndIndex[i];
527
- if ((startIndex === 0) || (input[startIndex - 1] !== "\\")) {
528
- for (let j = i + 1; j < backticksLengthAndIndex.length; j++) {
529
- const [ endLength, endIndex ] = backticksLengthAndIndex[j];
530
- if (startLength === endLength) {
531
- for (; k < newLinesIndex.length; k++) {
532
- const newLineIndex = newLinesIndex[k];
533
- if (startIndex < newLineIndex) {
534
- break;
535
- }
536
- lineIndex++;
537
- lineStartIndex = newLineIndex + 1;
538
- }
539
- const columnIndex = startIndex - lineStartIndex + startLength;
540
- handler(
541
- input.slice(startIndex + startLength, endIndex),
542
- lineIndex,
543
- columnIndex,
544
- startLength
545
- );
546
- i = j;
547
- break;
548
- }
549
- }
550
- }
551
- }
552
- }
553
- module.exports.forEachInlineCodeSpan = forEachInlineCodeSpan;
554
-
555
- /**
556
- * Adds ellipsis to the left/right/middle of the specified text.
557
- *
558
- * @param {string} text Text to ellipsify.
559
- * @param {boolean} [start] True iff the start of the text is important.
560
- * @param {boolean} [end] True iff the end of the text is important.
561
- * @returns {string} Ellipsified text.
562
- */
563
- function ellipsify(text, start, end) {
564
- if (text.length <= 30) {
565
- // Nothing to do
566
- } else if (start && end) {
567
- text = text.slice(0, 15) + "..." + text.slice(-15);
568
- } else if (end) {
569
- text = "..." + text.slice(-30);
570
- } else {
571
- text = text.slice(0, 30) + "...";
572
- }
573
- return text;
574
- }
575
- module.exports.ellipsify = ellipsify;
576
-
577
- /**
578
- * Adds a generic error object via the onError callback.
579
- *
580
- * @param {Object} onError RuleOnError instance.
581
- * @param {number} lineNumber Line number.
582
- * @param {string} [detail] Error details.
583
- * @param {string} [context] Error context.
584
- * @param {number[]} [range] Column and length of error.
585
- * @param {Object} [fixInfo] RuleOnErrorFixInfo instance.
586
- * @returns {void}
587
- */
588
- function addError(onError, lineNumber, detail, context, range, fixInfo) {
589
- onError({
590
- lineNumber,
591
- detail,
592
- context,
593
- range,
594
- fixInfo
595
- });
596
- }
597
- module.exports.addError = addError;
598
-
599
- // Adds an error object with details conditionally via the onError callback
600
- module.exports.addErrorDetailIf = function addErrorDetailIf(
601
- onError, lineNumber, expected, actual, detail, context, range, fixInfo) {
602
- if (expected !== actual) {
603
- addError(
604
- onError,
605
- lineNumber,
606
- "Expected: " + expected + "; Actual: " + actual +
607
- (detail ? "; " + detail : ""),
608
- context,
609
- range,
610
- fixInfo);
611
- }
612
- };
613
-
614
- // Adds an error object with context via the onError callback
615
- module.exports.addErrorContext = function addErrorContext(
616
- onError, lineNumber, context, left, right, range, fixInfo) {
617
- context = ellipsify(context, left, right);
618
- addError(onError, lineNumber, undefined, context, range, fixInfo);
619
- };
620
-
621
- /**
622
- * Returns an array of code block and span content ranges.
623
- *
624
- * @param {Object} params RuleParams instance.
625
- * @param {Object} lineMetadata Line metadata object.
626
- * @returns {number[][]} Array of ranges (lineIndex, columnIndex, length).
627
- */
628
- module.exports.codeBlockAndSpanRanges = (params, lineMetadata) => {
629
- const exclusions = [];
630
- // Add code block ranges (excludes fences)
631
- forEachLine(lineMetadata, (line, lineIndex, inCode, onFence) => {
632
- if (inCode && !onFence) {
633
- exclusions.push([ lineIndex, 0, line.length ]);
634
- }
635
- });
636
- // Add code span ranges (excludes ticks)
637
- filterTokens(params, "inline", (token) => {
638
- if (token.children.some((child) => child.type === "code_inline")) {
639
- const tokenLines = params.lines.slice(token.map[0], token.map[1]);
640
- forEachInlineCodeSpan(
641
- tokenLines.join("\n"),
642
- (code, lineIndex, columnIndex) => {
643
- const codeLines = code.split(newLineRe);
644
- for (const [ i, line ] of codeLines.entries()) {
645
- exclusions.push([
646
- token.lineNumber - 1 + lineIndex + i,
647
- i ? 0 : columnIndex,
648
- line.length
649
- ]);
650
- }
651
- }
652
- );
653
- }
654
- });
655
- return exclusions;
656
- };
657
-
658
- /**
659
- * Determines whether the specified range is within another range.
660
- *
661
- * @param {number[][]} ranges Array of ranges (line, index, length).
662
- * @param {number} lineIndex Line index to check.
663
- * @param {number} index Index to check.
664
- * @param {number} length Length to check.
665
- * @returns {boolean} True iff the specified range is within.
666
- */
667
- const withinAnyRange = (ranges, lineIndex, index, length) => (
668
- !ranges.every((span) => (
669
- (lineIndex !== span[0]) ||
670
- (index < span[1]) ||
671
- (index + length > span[1] + span[2])
672
- ))
673
- );
674
- module.exports.withinAnyRange = withinAnyRange;
675
-
676
- // Returns a range object for a line by applying a RegExp
677
- module.exports.rangeFromRegExp = function rangeFromRegExp(line, regexp) {
678
- let range = null;
679
- const match = line.match(regexp);
680
- if (match) {
681
- const column = match.index + 1;
682
- const length = match[0].length;
683
- range = [ column, length ];
684
- }
685
- return range;
686
- };
687
-
688
- // Determines if the front matter includes a title
689
- module.exports.frontMatterHasTitle =
690
- function frontMatterHasTitle(frontMatterLines, frontMatterTitlePattern) {
691
- const ignoreFrontMatter =
692
- (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern;
693
- const frontMatterTitleRe =
694
- new RegExp(
695
- String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"),
696
- "i"
697
- );
698
- return !ignoreFrontMatter &&
699
- frontMatterLines.some((line) => frontMatterTitleRe.test(line));
700
- };
701
-
702
- /**
703
- * Returns an object with information about reference links and images.
704
- *
705
- * @param {Object} params RuleParams instance.
706
- * @returns {Object} Reference link/image data.
707
- */
708
- function getReferenceLinkImageData(params) {
709
- const normalizeReference = (s) => s.toLowerCase().trim().replace(/\s+/g, " ");
710
- const definitions = new Map();
711
- const definitionLineIndices = [];
712
- const duplicateDefinitions = [];
713
- const references = new Map();
714
- const shortcuts = new Map();
715
- const filteredTokens =
716
- micromark.filterByTypes(
717
- params.parsers.micromark.tokens,
718
- [
719
- // definitionLineIndices
720
- "definition", "gfmFootnoteDefinition",
721
- // definitions and definitionLineIndices
722
- "definitionLabelString", "gfmFootnoteDefinitionLabelString",
723
- // references and shortcuts
724
- "gfmFootnoteCall", "image", "link"
725
- ]
726
- );
727
- for (const token of filteredTokens) {
728
- let labelPrefix = "";
729
- // eslint-disable-next-line default-case
730
- switch (token.type) {
731
- case "definition":
732
- case "gfmFootnoteDefinition":
733
- // definitionLineIndices
734
- for (let i = token.startLine; i <= token.endLine; i++) {
735
- definitionLineIndices.push(i - 1);
736
- }
737
- break;
738
- case "gfmFootnoteDefinitionLabelString":
739
- labelPrefix = "^";
740
- case "definitionLabelString": // eslint-disable-line no-fallthrough
741
- {
742
- // definitions and definitionLineIndices
743
- const reference = normalizeReference(`${labelPrefix}${token.text}`);
744
- if (definitions.has(reference)) {
745
- duplicateDefinitions.push([ reference, token.startLine - 1 ]);
746
- } else {
747
- let destinationString = null;
748
- const parent =
749
- micromark.getTokenParentOfType(token, [ "definition" ]);
750
- if (parent) {
751
- destinationString = micromark.getTokenTextByType(
752
- micromark.filterByPredicate(parent.children),
753
- "definitionDestinationString"
754
- );
755
- }
756
- definitions.set(
757
- reference,
758
- [ token.startLine - 1, destinationString ]
759
- );
760
- }
761
- }
762
- break;
763
- case "gfmFootnoteCall":
764
- case "image":
765
- case "link":
766
- {
767
- let isShortcut = false;
768
- let isFullOrCollapsed = false;
769
- let labelText = null;
770
- let referenceStringText = null;
771
- const shortcutCandidate =
772
- micromark.matchAndGetTokensByType(token.children, [ "label" ]);
773
- if (shortcutCandidate) {
774
- labelText =
775
- micromark.getTokenTextByType(
776
- shortcutCandidate[0].children, "labelText"
777
- );
778
- isShortcut = (labelText !== null);
779
- }
780
- const fullAndCollapsedCandidate =
781
- micromark.matchAndGetTokensByType(
782
- token.children, [ "label", "reference" ]
783
- );
784
- if (fullAndCollapsedCandidate) {
785
- labelText =
786
- micromark.getTokenTextByType(
787
- fullAndCollapsedCandidate[0].children, "labelText"
788
- );
789
- referenceStringText =
790
- micromark.getTokenTextByType(
791
- fullAndCollapsedCandidate[1].children, "referenceString"
792
- );
793
- isFullOrCollapsed = (labelText !== null);
794
- }
795
- const footnote = micromark.matchAndGetTokensByType(
796
- token.children,
797
- [
798
- "gfmFootnoteCallLabelMarker", "gfmFootnoteCallMarker",
799
- "gfmFootnoteCallString", "gfmFootnoteCallLabelMarker"
800
- ],
801
- [ "gfmFootnoteCallMarker", "gfmFootnoteCallString" ]
802
- );
803
- if (footnote) {
804
- const callMarkerText = footnote[0].text;
805
- const callString = footnote[1].text;
806
- labelText = `${callMarkerText}${callString}`;
807
- isShortcut = true;
808
- }
809
- // Track shortcuts separately due to ambiguity in "text [text] text"
810
- if (isShortcut || isFullOrCollapsed) {
811
- const referenceDatum = [
812
- token.startLine - 1,
813
- token.startColumn - 1,
814
- token.text.length,
815
- // @ts-ignore
816
- labelText.length,
817
- (referenceStringText || "").length
818
- ];
819
- const reference =
820
- normalizeReference(referenceStringText || labelText);
821
- const dictionary = isShortcut ? shortcuts : references;
822
- const referenceData = dictionary.get(reference) || [];
823
- referenceData.push(referenceDatum);
824
- dictionary.set(reference, referenceData);
825
- }
826
- }
827
- break;
828
- }
829
- }
830
- return {
831
- references,
832
- shortcuts,
833
- definitions,
834
- duplicateDefinitions,
835
- definitionLineIndices
836
- };
837
- }
838
- module.exports.getReferenceLinkImageData = getReferenceLinkImageData;
839
-
840
- /**
841
- * Gets the most common line ending, falling back to the platform default.
842
- *
843
- * @param {string} input Markdown content to analyze.
844
- * @param {Object} [os] Node.js "os" module.
845
- * @returns {string} Preferred line ending.
846
- */
847
- function getPreferredLineEnding(input, os) {
848
- let cr = 0;
849
- let lf = 0;
850
- let crlf = 0;
851
- const endings = input.match(newLineRe) || [];
852
- for (const ending of endings) {
853
- // eslint-disable-next-line default-case
854
- switch (ending) {
855
- case "\r":
856
- cr++;
857
- break;
858
- case "\n":
859
- lf++;
860
- break;
861
- case "\r\n":
862
- crlf++;
863
- break;
864
- }
865
- }
866
- let preferredLineEnding = null;
867
- if (!cr && !lf && !crlf) {
868
- preferredLineEnding = (os && os.EOL) || "\n";
869
- } else if ((lf >= crlf) && (lf >= cr)) {
870
- preferredLineEnding = "\n";
871
- } else if (crlf >= cr) {
872
- preferredLineEnding = "\r\n";
873
- } else {
874
- preferredLineEnding = "\r";
875
- }
876
- return preferredLineEnding;
877
- }
878
- module.exports.getPreferredLineEnding = getPreferredLineEnding;
879
-
880
- /**
881
- * Normalizes the fields of a RuleOnErrorFixInfo instance.
882
- *
883
- * @param {Object} fixInfo RuleOnErrorFixInfo instance.
884
- * @param {number} [lineNumber] Line number.
885
- * @returns {Object} Normalized RuleOnErrorFixInfo instance.
886
- */
887
- function normalizeFixInfo(fixInfo, lineNumber) {
888
- return {
889
- "lineNumber": fixInfo.lineNumber || lineNumber,
890
- "editColumn": fixInfo.editColumn || 1,
891
- "deleteCount": fixInfo.deleteCount || 0,
892
- "insertText": fixInfo.insertText || ""
893
- };
894
- }
895
-
896
- /**
897
- * Fixes the specified error on a line of Markdown content.
898
- *
899
- * @param {string} line Line of Markdown content.
900
- * @param {Object} fixInfo RuleOnErrorFixInfo instance.
901
- * @param {string} [lineEnding] Line ending to use.
902
- * @returns {string | null} Fixed content.
903
- */
904
- function applyFix(line, fixInfo, lineEnding) {
905
- const { editColumn, deleteCount, insertText } = normalizeFixInfo(fixInfo);
906
- const editIndex = editColumn - 1;
907
- return (deleteCount === -1) ?
908
- null :
909
- line.slice(0, editIndex) +
910
- insertText.replace(/\n/g, lineEnding || "\n") +
911
- line.slice(editIndex + deleteCount);
912
- }
913
- module.exports.applyFix = applyFix;
914
-
915
- /**
916
- * Applies as many fixes as possible to Markdown content.
917
- *
918
- * @param {string} input Lines of Markdown content.
919
- * @param {Object[]} errors RuleOnErrorInfo instances.
920
- * @returns {string} Corrected content.
921
- */
922
- function applyFixes(input, errors) {
923
- const lineEnding = getPreferredLineEnding(input, require("node:os"));
924
- const lines = input.split(newLineRe);
925
- // Normalize fixInfo objects
926
- let fixInfos = errors
927
- .filter((error) => error.fixInfo)
928
- .map((error) => normalizeFixInfo(error.fixInfo, error.lineNumber));
929
- // Sort bottom-to-top, line-deletes last, right-to-left, long-to-short
930
- fixInfos.sort((a, b) => {
931
- const aDeletingLine = (a.deleteCount === -1);
932
- const bDeletingLine = (b.deleteCount === -1);
933
- return (
934
- (b.lineNumber - a.lineNumber) ||
935
- (aDeletingLine ? 1 : (bDeletingLine ? -1 : 0)) ||
936
- (b.editColumn - a.editColumn) ||
937
- (b.insertText.length - a.insertText.length)
938
- );
939
- });
940
- // Remove duplicate entries (needed for following collapse step)
941
- let lastFixInfo = {};
942
- fixInfos = fixInfos.filter((fixInfo) => {
943
- const unique = (
944
- (fixInfo.lineNumber !== lastFixInfo.lineNumber) ||
945
- (fixInfo.editColumn !== lastFixInfo.editColumn) ||
946
- (fixInfo.deleteCount !== lastFixInfo.deleteCount) ||
947
- (fixInfo.insertText !== lastFixInfo.insertText)
948
- );
949
- lastFixInfo = fixInfo;
950
- return unique;
951
- });
952
- // Collapse insert/no-delete and no-insert/delete for same line/column
953
- lastFixInfo = {
954
- "lineNumber": -1
955
- };
956
- for (const fixInfo of fixInfos) {
957
- if (
958
- (fixInfo.lineNumber === lastFixInfo.lineNumber) &&
959
- (fixInfo.editColumn === lastFixInfo.editColumn) &&
960
- !fixInfo.insertText &&
961
- (fixInfo.deleteCount > 0) &&
962
- lastFixInfo.insertText &&
963
- !lastFixInfo.deleteCount) {
964
- fixInfo.insertText = lastFixInfo.insertText;
965
- lastFixInfo.lineNumber = 0;
966
- }
967
- lastFixInfo = fixInfo;
968
- }
969
- fixInfos = fixInfos.filter((fixInfo) => fixInfo.lineNumber);
970
- // Apply all (remaining/updated) fixes
971
- let lastLineIndex = -1;
972
- let lastEditIndex = -1;
973
- for (const fixInfo of fixInfos) {
974
- const { lineNumber, editColumn, deleteCount } = fixInfo;
975
- const lineIndex = lineNumber - 1;
976
- const editIndex = editColumn - 1;
977
- if (
978
- (lineIndex !== lastLineIndex) ||
979
- (deleteCount === -1) ||
980
- ((editIndex + deleteCount) <=
981
- (lastEditIndex - ((deleteCount > 0) ? 0 : 1)))
982
- ) {
983
- // @ts-ignore
984
- lines[lineIndex] = applyFix(lines[lineIndex], fixInfo, lineEnding);
985
- }
986
- lastLineIndex = lineIndex;
987
- lastEditIndex = editIndex;
988
- }
989
- // Return corrected input
990
- return lines.filter((line) => line !== null).join(lineEnding);
991
- }
992
- module.exports.applyFixes = applyFixes;
993
-
994
- /**
995
- * Expands a path with a tilde to an absolute path.
996
- *
997
- * @param {string} file Path that may begin with a tilde.
998
- * @param {Object} os Node.js "os" module.
999
- * @returns {string} Absolute path (or original path).
1000
- */
1001
- function expandTildePath(file, os) {
1002
- const homedir = os && os.homedir && os.homedir();
1003
- return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
1004
- }
1005
- module.exports.expandTildePath = expandTildePath;
1006
-
1007
- // Copied from markdownlint.js to avoid TypeScript compiler import() issue.
1008
- /**
1009
- * @typedef {Object} MarkdownItToken
1010
- * @property {string[][]} attrs HTML attributes.
1011
- * @property {boolean} block Block-level token.
1012
- * @property {MarkdownItToken[]} children Child nodes.
1013
- * @property {string} content Tag contents.
1014
- * @property {boolean} hidden Ignore element.
1015
- * @property {string} info Fence info.
1016
- * @property {number} level Nesting level.
1017
- * @property {number[]} map Beginning/ending line numbers.
1018
- * @property {string} markup Markup text.
1019
- * @property {Object} meta Arbitrary data.
1020
- * @property {number} nesting Level change.
1021
- * @property {string} tag HTML tag name.
1022
- * @property {string} type Token type.
1023
- * @property {number} lineNumber Line number (1-based).
1024
- * @property {string} line Line content.
1025
- */