@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,1476 +0,0 @@
1
- // @ts-check
2
-
3
- "use strict";
4
-
5
- const path = require("node:path");
6
- const { promisify } = require("node:util");
7
- const markdownit = require("markdown-it");
8
- const micromark = require("../helpers/micromark.cjs");
9
- // const { deprecatedRuleNames } = require("./constants");
10
- const rules = require("./rules");
11
- const helpers = require("../helpers");
12
- const cache = require("./cache");
13
-
14
- // @ts-ignore
15
- // eslint-disable-next-line camelcase, no-inline-comments, no-undef
16
- const dynamicRequire = (typeof __non_webpack_require__ === "undefined") ? require : /* c8 ignore next */ __non_webpack_require__;
17
- // Capture native require implementation for dynamic loading of modules
18
-
19
- /**
20
- * Validate the list of rules for structure and reuse.
21
- *
22
- * @param {Rule[]} ruleList List of rules.
23
- * @param {boolean} synchronous Whether to execute synchronously.
24
- * @returns {Error | null} Error message if validation fails.
25
- */
26
- function validateRuleList(ruleList, synchronous) {
27
- let result = null;
28
- if (ruleList.length === rules.length) {
29
- // No need to validate if only using built-in rules
30
- return result;
31
- }
32
- const allIds = {};
33
- for (const [ index, rule ] of ruleList.entries()) {
34
- const customIndex = index - rules.length;
35
- // eslint-disable-next-line no-inner-declarations, jsdoc/require-jsdoc
36
- function newError(property) {
37
- return new Error(
38
- "Property '" + property + "' of custom rule at index " +
39
- customIndex + " is incorrect.");
40
- }
41
- for (const property of [ "names", "tags" ]) {
42
- const value = rule[property];
43
- if (!result &&
44
- (!value || !Array.isArray(value) || (value.length === 0) ||
45
- !value.every(helpers.isString) || value.some(helpers.isEmptyString))) {
46
- result = newError(property);
47
- }
48
- }
49
- for (const propertyInfo of [
50
- [ "description", "string" ],
51
- [ "function", "function" ]
52
- ]) {
53
- const property = propertyInfo[0];
54
- const value = rule[property];
55
- if (!result && (!value || (typeof value !== propertyInfo[1]))) {
56
- result = newError(property);
57
- }
58
- }
59
- if (
60
- !result &&
61
- rule.information &&
62
- !helpers.isUrl(rule.information)
63
- ) {
64
- result = newError("information");
65
- }
66
- if (
67
- !result &&
68
- (rule.asynchronous !== undefined) &&
69
- (typeof rule.asynchronous !== "boolean")
70
- ) {
71
- result = newError("asynchronous");
72
- }
73
- if (!result && rule.asynchronous && synchronous) {
74
- result = new Error(
75
- "Custom rule " + rule.names.join("/") + " at index " + customIndex +
76
- " is asynchronous and can not be used in a synchronous context."
77
- );
78
- }
79
- if (!result) {
80
- for (const name of rule.names) {
81
- const nameUpper = name.toUpperCase();
82
- if (!result && (allIds[nameUpper] !== undefined)) {
83
- result = new Error("Name '" + name + "' of custom rule at index " +
84
- customIndex + " is already used as a name or tag.");
85
- }
86
- allIds[nameUpper] = true;
87
- }
88
- for (const tag of rule.tags) {
89
- const tagUpper = tag.toUpperCase();
90
- if (!result && allIds[tagUpper]) {
91
- result = new Error("Tag '" + tag + "' of custom rule at index " +
92
- customIndex + " is already used as a name.");
93
- }
94
- allIds[tagUpper] = false;
95
- }
96
- }
97
- }
98
- return result;
99
- }
100
-
101
- /**
102
- * Creates a LintResults instance with toString for pretty display.
103
- *
104
- * @param {Rule[]} ruleList List of rules.
105
- * @returns {LintResults} New LintResults instance.
106
- */
107
- function newResults(ruleList) {
108
- const lintResults = {};
109
- // eslint-disable-next-line jsdoc/require-jsdoc
110
- function toString(useAlias) {
111
- let ruleNameToRule = null;
112
- const results = [];
113
- const keys = Object.keys(lintResults);
114
- keys.sort();
115
- for (const file of keys) {
116
- const fileResults = lintResults[file];
117
- if (Array.isArray(fileResults)) {
118
- for (const result of fileResults) {
119
- const ruleMoniker = result.ruleNames ?
120
- result.ruleNames.join("/") :
121
- (result.ruleName + "/" + result.ruleAlias);
122
- results.push(
123
- file + ": " +
124
- result.lineNumber + ": " +
125
- ruleMoniker + " " +
126
- result.ruleDescription +
127
- (result.errorDetail ?
128
- " [" + result.errorDetail + "]" :
129
- "") +
130
- (result.errorContext ?
131
- " [Context: \"" + result.errorContext + "\"]" :
132
- ""));
133
- }
134
- } else {
135
- if (!ruleNameToRule) {
136
- ruleNameToRule = {};
137
- for (const rule of ruleList) {
138
- const ruleName = rule.names[0].toUpperCase();
139
- ruleNameToRule[ruleName] = rule;
140
- }
141
- }
142
- for (const [ ruleName, ruleResults ] of Object.entries(fileResults)) {
143
- const rule = ruleNameToRule[ruleName.toUpperCase()];
144
- for (const lineNumber of ruleResults) {
145
- // @ts-ignore
146
- const nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1);
147
- const result =
148
- file + ": " +
149
- lineNumber + ": " +
150
- // @ts-ignore
151
- rule.names[nameIndex] + " " +
152
- // @ts-ignore
153
- rule.description;
154
- results.push(result);
155
- }
156
- }
157
- }
158
- }
159
- return results.join("\n");
160
- }
161
- Object.defineProperty(lintResults, "toString", { "value": toString });
162
- // @ts-ignore
163
- return lintResults;
164
- }
165
-
166
- /**
167
- * Remove front matter (if present at beginning of content).
168
- *
169
- * @param {string} content Markdown content.
170
- * @param {RegExp | null} frontMatter Regular expression to match front matter.
171
- * @returns {Object} Trimmed content and front matter lines.
172
- */
173
- function removeFrontMatter(content, frontMatter) {
174
- let frontMatterLines = [];
175
- if (frontMatter) {
176
- const frontMatterMatch = content.match(frontMatter);
177
- if (frontMatterMatch && !frontMatterMatch.index) {
178
- const contentMatched = frontMatterMatch[0];
179
- content = content.slice(contentMatched.length);
180
- frontMatterLines = contentMatched.split(helpers.newLineRe);
181
- if ((frontMatterLines.length > 0) &&
182
- (frontMatterLines[frontMatterLines.length - 1] === "")) {
183
- frontMatterLines.length--;
184
- }
185
- }
186
- }
187
- return {
188
- "content": content,
189
- "frontMatterLines": frontMatterLines
190
- };
191
- }
192
-
193
- /**
194
- * Freeze all freeze-able members of a token and its children.
195
- *
196
- * @param {MarkdownItToken} token A markdown-it token.
197
- * @returns {void}
198
- */
199
- function freezeToken(token) {
200
- if (token.attrs) {
201
- for (const attr of token.attrs) {
202
- Object.freeze(attr);
203
- }
204
- Object.freeze(token.attrs);
205
- }
206
- if (token.children) {
207
- for (const child of token.children) {
208
- freezeToken(child);
209
- }
210
- Object.freeze(token.children);
211
- }
212
- if (token.map) {
213
- Object.freeze(token.map);
214
- }
215
- Object.freeze(token);
216
- }
217
-
218
- /**
219
- * Annotate tokens with line/lineNumber and freeze them.
220
- *
221
- * @param {MarkdownItToken[]} tokens Array of markdown-it tokens.
222
- * @param {string[]} lines Lines of Markdown content.
223
- * @returns {void}
224
- */
225
- function annotateAndFreezeTokens(tokens, lines) {
226
- let trMap = null;
227
- for (const token of tokens) {
228
- // Provide missing maps for table content
229
- if (token.type === "tr_open") {
230
- trMap = token.map;
231
- } else if (token.type === "tr_close") {
232
- trMap = null;
233
- }
234
- if (!token.map && trMap) {
235
- token.map = [ ...trMap ];
236
- }
237
- // Update token metadata
238
- if (token.map) {
239
- token.line = lines[token.map[0]];
240
- token.lineNumber = token.map[0] + 1;
241
- // Trim bottom of token to exclude whitespace lines
242
- while (token.map[1] && !((lines[token.map[1] - 1] || "").trim())) {
243
- token.map[1]--;
244
- }
245
- }
246
- // Annotate children with lineNumber
247
- if (token.children) {
248
- const codeSpanExtraLines = [];
249
- if (token.children.some((child) => child.type === "code_inline")) {
250
- helpers.forEachInlineCodeSpan(token.content, (code) => {
251
- codeSpanExtraLines.push(code.split(helpers.newLineRe).length - 1);
252
- });
253
- }
254
- let lineNumber = token.lineNumber;
255
- for (const child of token.children) {
256
- child.lineNumber = lineNumber;
257
- child.line = lines[lineNumber - 1];
258
- if ((child.type === "softbreak") || (child.type === "hardbreak")) {
259
- lineNumber++;
260
- } else if (child.type === "code_inline") {
261
- lineNumber += codeSpanExtraLines.shift();
262
- }
263
- }
264
- }
265
- freezeToken(token);
266
- }
267
- Object.freeze(tokens);
268
- }
269
-
270
- /**
271
- * Map rule names/tags to canonical rule name.
272
- *
273
- * @param {Rule[]} ruleList List of rules.
274
- * @returns {Object.<string, string[]>} Map of alias to rule name.
275
- */
276
- function mapAliasToRuleNames(ruleList) {
277
- const aliasToRuleNames = {};
278
- // const tagToRuleNames = {};
279
- for (const rule of ruleList) {
280
- const ruleName = rule.names[0].toUpperCase();
281
- // The following is useful for updating README.md:
282
- // console.log(
283
- // "* **[" + ruleName + "](doc/Rules.md#" + ruleName.toLowerCase() +
284
- // ")** *" + rule.names.slice(1).join("/") + "* - " + rule.description);
285
- for (const name of rule.names) {
286
- const nameUpper = name.toUpperCase();
287
- aliasToRuleNames[nameUpper] = [ ruleName ];
288
- }
289
- for (const tag of rule.tags) {
290
- const tagUpper = tag.toUpperCase();
291
- const ruleNames = aliasToRuleNames[tagUpper] || [];
292
- ruleNames.push(ruleName);
293
- aliasToRuleNames[tagUpper] = ruleNames;
294
- // tagToRuleNames[tag] = ruleName;
295
- }
296
- }
297
- // The following is useful for updating README.md:
298
- // Object.keys(tagToRuleNames).sort().forEach(function forTag(tag) {
299
- // console.log("* **" + tag + "** - " +
300
- // aliasToRuleNames[tag.toUpperCase()].join(", "));
301
- // });
302
- // @ts-ignore
303
- return aliasToRuleNames;
304
- }
305
-
306
- /**
307
- * Apply (and normalize) configuration object.
308
- *
309
- * @param {Rule[]} ruleList List of rules.
310
- * @param {Configuration} config Configuration object.
311
- * @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
312
- * names.
313
- * @returns {Configuration} Effective configuration.
314
- */
315
- function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
316
- const defaultKey = Object.keys(config).filter(
317
- (key) => key.toUpperCase() === "DEFAULT"
318
- );
319
- const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]];
320
- /** @type {Configuration} */
321
- const effectiveConfig = {};
322
- for (const rule of ruleList) {
323
- const ruleName = rule.names[0].toUpperCase();
324
- effectiveConfig[ruleName] = ruleDefault;
325
- }
326
- // for (const ruleName of deprecatedRuleNames) {
327
- // effectiveConfig[ruleName] = false;
328
- // }
329
- for (const key of Object.keys(config)) {
330
- let value = config[key];
331
- if (value) {
332
- if (!(value instanceof Object)) {
333
- value = {};
334
- }
335
- } else {
336
- value = false;
337
- }
338
- const keyUpper = key.toUpperCase();
339
- for (const ruleName of (aliasToRuleNames[keyUpper] || [])) {
340
- effectiveConfig[ruleName] = value;
341
- }
342
- }
343
- return effectiveConfig;
344
- }
345
-
346
- /**
347
- * Parse the content of a configuration file.
348
- *
349
- * @param {string} name Name of the configuration file.
350
- * @param {string} content Configuration content.
351
- * @param {ConfigurationParser[] | null} [parsers] Parsing function(s).
352
- * @returns {Object} Configuration object and error message.
353
- */
354
- function parseConfiguration(name, content, parsers) {
355
- let config = null;
356
- let message = "";
357
- const errors = [];
358
- let index = 0;
359
- // Try each parser
360
- (parsers || [ JSON.parse ]).every((parser) => {
361
- try {
362
- config = parser(content);
363
- } catch (error) {
364
- errors.push(`Parser ${index++}: ${error.message}`);
365
- }
366
- return !config;
367
- });
368
- // Message if unable to parse
369
- if (!config) {
370
- errors.unshift(`Unable to parse '${name}'`);
371
- message = errors.join("; ");
372
- }
373
- return {
374
- config,
375
- message
376
- };
377
- }
378
-
379
- /**
380
- * Create a mapping of enabled rules per line.
381
- *
382
- * @param {Rule[]} ruleList List of rules.
383
- * @param {string[]} lines List of content lines.
384
- * @param {string[]} frontMatterLines List of front matter lines.
385
- * @param {boolean} noInlineConfig Whether to allow inline configuration.
386
- * @param {Configuration} config Configuration object.
387
- * @param {ConfigurationParser[] | null} configParsers Configuration parsers.
388
- * @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
389
- * names.
390
- * @returns {Object} Effective configuration and enabled rules per line number.
391
- */
392
- function getEnabledRulesPerLineNumber(
393
- ruleList,
394
- lines,
395
- frontMatterLines,
396
- noInlineConfig,
397
- config,
398
- configParsers,
399
- aliasToRuleNames) {
400
- // Shared variables
401
- let enabledRules = {};
402
- let capturedRules = {};
403
- const allRuleNames = [];
404
- const enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
405
- // Helper functions
406
- // eslint-disable-next-line jsdoc/require-jsdoc
407
- function handleInlineConfig(input, forEachMatch, forEachLine) {
408
- for (const [ lineIndex, line ] of input.entries()) {
409
- if (!noInlineConfig) {
410
- let match = null;
411
- while ((match = helpers.inlineCommentStartRe.exec(line))) {
412
- const action = match[2].toUpperCase();
413
- const startIndex = match.index + match[1].length;
414
- const endIndex = line.indexOf("-->", startIndex);
415
- if (endIndex === -1) {
416
- break;
417
- }
418
- const parameter = line.slice(startIndex, endIndex);
419
- forEachMatch(action, parameter, lineIndex + 1);
420
- }
421
- }
422
- if (forEachLine) {
423
- forEachLine();
424
- }
425
- }
426
- }
427
- // eslint-disable-next-line jsdoc/require-jsdoc
428
- function configureFile(action, parameter) {
429
- if (action === "CONFIGURE-FILE") {
430
- const { "config": parsed } = parseConfiguration(
431
- "CONFIGURE-FILE", parameter, configParsers
432
- );
433
- if (parsed) {
434
- config = {
435
- ...config,
436
- ...parsed
437
- };
438
- }
439
- }
440
- }
441
- // eslint-disable-next-line jsdoc/require-jsdoc
442
- function applyEnableDisable(action, parameter, state) {
443
- state = { ...state };
444
- const enabled = (action.startsWith("ENABLE"));
445
- const trimmed = parameter && parameter.trim();
446
- const items = trimmed ? trimmed.toUpperCase().split(/\s+/) : allRuleNames;
447
- for (const nameUpper of items) {
448
- for (const ruleName of (aliasToRuleNames[nameUpper] || [])) {
449
- state[ruleName] = enabled;
450
- }
451
- }
452
- return state;
453
- }
454
- // eslint-disable-next-line jsdoc/require-jsdoc
455
- function enableDisableFile(action, parameter) {
456
- if ((action === "ENABLE-FILE") || (action === "DISABLE-FILE")) {
457
- enabledRules = applyEnableDisable(action, parameter, enabledRules);
458
- }
459
- }
460
- // eslint-disable-next-line jsdoc/require-jsdoc
461
- function captureRestoreEnableDisable(action, parameter) {
462
- if (action === "CAPTURE") {
463
- capturedRules = enabledRules;
464
- } else if (action === "RESTORE") {
465
- enabledRules = capturedRules;
466
- } else if ((action === "ENABLE") || (action === "DISABLE")) {
467
- enabledRules = applyEnableDisable(action, parameter, enabledRules);
468
- }
469
- }
470
- // eslint-disable-next-line jsdoc/require-jsdoc
471
- function updateLineState() {
472
- enabledRulesPerLineNumber.push(enabledRules);
473
- }
474
- // eslint-disable-next-line jsdoc/require-jsdoc
475
- function disableLineNextLine(action, parameter, lineNumber) {
476
- const disableLine = (action === "DISABLE-LINE");
477
- const disableNextLine = (action === "DISABLE-NEXT-LINE");
478
- if (disableLine || disableNextLine) {
479
- const nextLineNumber =
480
- frontMatterLines.length + lineNumber + (disableNextLine ? 1 : 0);
481
- enabledRulesPerLineNumber[nextLineNumber] =
482
- applyEnableDisable(
483
- action,
484
- parameter,
485
- enabledRulesPerLineNumber[nextLineNumber]
486
- );
487
- }
488
- }
489
- // Handle inline comments
490
- handleInlineConfig([ lines.join("\n") ], configureFile);
491
- const effectiveConfig = getEffectiveConfig(
492
- ruleList, config, aliasToRuleNames);
493
- for (const rule of ruleList) {
494
- const ruleName = rule.names[0].toUpperCase();
495
- allRuleNames.push(ruleName);
496
- enabledRules[ruleName] = !!effectiveConfig[ruleName];
497
- }
498
- capturedRules = enabledRules;
499
- handleInlineConfig(lines, enableDisableFile);
500
- handleInlineConfig(lines, captureRestoreEnableDisable, updateLineState);
501
- handleInlineConfig(lines, disableLineNextLine);
502
- // Return results
503
- return {
504
- effectiveConfig,
505
- enabledRulesPerLineNumber
506
- };
507
- }
508
-
509
- /**
510
- * Lints a string containing Markdown content.
511
- *
512
- * @param {Rule[]} ruleList List of rules.
513
- * @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
514
- * names.
515
- * @param {string} name Identifier for the content.
516
- * @param {string} content Markdown content.
517
- * @param {Object} md Instance of markdown-it.
518
- * @param {Configuration} config Configuration object.
519
- * @param {ConfigurationParser[] | null} configParsers Configuration parsers.
520
- * @param {RegExp | null} frontMatter Regular expression for front matter.
521
- * @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
522
- * @param {boolean} noInlineConfig Whether to allow inline configuration.
523
- * @param {number} resultVersion Version of the LintResults object to return.
524
- * @param {LintContentCallback} callback Callback (err, result) function.
525
- * @returns {void}
526
- */
527
- function lintContent(
528
- ruleList,
529
- aliasToRuleNames,
530
- name,
531
- content,
532
- md,
533
- config,
534
- configParsers,
535
- frontMatter,
536
- handleRuleFailures,
537
- noInlineConfig,
538
- resultVersion,
539
- callback) {
540
- // Remove UTF-8 byte order marker (if present)
541
- content = content.replace(/^\uFEFF/, "");
542
- // Remove front matter
543
- const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
544
- const { frontMatterLines } = removeFrontMatterResult;
545
- content = removeFrontMatterResult.content;
546
- // Get enabled rules per line (with HTML comments present)
547
- const { effectiveConfig, enabledRulesPerLineNumber } =
548
- getEnabledRulesPerLineNumber(
549
- ruleList,
550
- content.split(helpers.newLineRe),
551
- frontMatterLines,
552
- noInlineConfig,
553
- config,
554
- configParsers,
555
- aliasToRuleNames
556
- );
557
- // Parse content into parser tokens
558
- const markdownitTokens = md.parse(content, {});
559
- const micromarkTokens = micromark.parse(content);
560
- // Hide the content of HTML comments from rules
561
- content = helpers.clearHtmlCommentText(content);
562
- // Parse content into lines and update markdown-it tokens
563
- const lines = content.split(helpers.newLineRe);
564
- annotateAndFreezeTokens(markdownitTokens, lines);
565
- // Create (frozen) parameters for rules
566
- const parsers = Object.freeze({
567
- "markdownit": Object.freeze({
568
- "tokens": markdownitTokens
569
- }),
570
- "micromark": Object.freeze({
571
- "tokens": micromarkTokens
572
- })
573
- });
574
- const paramsBase = {
575
- name,
576
- parsers,
577
- "tokens": markdownitTokens,
578
- "lines": Object.freeze(lines),
579
- "frontMatterLines": Object.freeze(frontMatterLines)
580
- };
581
- const lineMetadata =
582
- helpers.getLineMetadata(paramsBase);
583
- const codeBlockAndSpanRanges =
584
- helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata);
585
- const flattenedLists =
586
- helpers.flattenLists(paramsBase.parsers.markdownit.tokens);
587
- const referenceLinkImageData =
588
- helpers.getReferenceLinkImageData(paramsBase);
589
- cache.set({
590
- codeBlockAndSpanRanges,
591
- flattenedLists,
592
- lineMetadata,
593
- referenceLinkImageData
594
- });
595
- // Function to run for each rule
596
- let results = [];
597
- // eslint-disable-next-line jsdoc/require-jsdoc
598
- function forRule(rule) {
599
- // Configure rule
600
- const ruleName = rule.names[0].toUpperCase();
601
- const params = {
602
- ...paramsBase,
603
- "config": effectiveConfig[ruleName]
604
- };
605
- // eslint-disable-next-line jsdoc/require-jsdoc
606
- function throwError(property) {
607
- throw new Error(
608
- `Value of '${property}' passed to onError by '${ruleName}' is incorrect for '${name}'.`);
609
- }
610
- // eslint-disable-next-line jsdoc/require-jsdoc
611
- function onError(errorInfo) {
612
- if (!errorInfo ||
613
- !helpers.isNumber(errorInfo.lineNumber) ||
614
- (errorInfo.lineNumber < 1) ||
615
- (errorInfo.lineNumber > lines.length)) {
616
- throwError("lineNumber");
617
- }
618
- const lineNumber = errorInfo.lineNumber + frontMatterLines.length;
619
- if (!enabledRulesPerLineNumber[lineNumber][ruleName]) {
620
- return;
621
- }
622
- if (errorInfo.detail &&
623
- !helpers.isString(errorInfo.detail)) {
624
- throwError("detail");
625
- }
626
- if (errorInfo.context &&
627
- !helpers.isString(errorInfo.context)) {
628
- throwError("context");
629
- }
630
- if (errorInfo.information &&
631
- !helpers.isUrl(errorInfo.information)) {
632
- throwError("information");
633
- }
634
- if (errorInfo.range &&
635
- (!Array.isArray(errorInfo.range) ||
636
- (errorInfo.range.length !== 2) ||
637
- !helpers.isNumber(errorInfo.range[0]) ||
638
- (errorInfo.range[0] < 1) ||
639
- !helpers.isNumber(errorInfo.range[1]) ||
640
- (errorInfo.range[1] < 1) ||
641
- ((errorInfo.range[0] + errorInfo.range[1] - 1) >
642
- lines[errorInfo.lineNumber - 1].length))) {
643
- throwError("range");
644
- }
645
- const fixInfo = errorInfo.fixInfo;
646
- const cleanFixInfo = {};
647
- if (fixInfo) {
648
- if (!helpers.isObject(fixInfo)) {
649
- throwError("fixInfo");
650
- }
651
- if (fixInfo.lineNumber !== undefined) {
652
- if ((!helpers.isNumber(fixInfo.lineNumber) ||
653
- (fixInfo.lineNumber < 1) ||
654
- (fixInfo.lineNumber > lines.length))) {
655
- throwError("fixInfo.lineNumber");
656
- }
657
- cleanFixInfo.lineNumber =
658
- fixInfo.lineNumber + frontMatterLines.length;
659
- }
660
- const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber;
661
- if (fixInfo.editColumn !== undefined) {
662
- if ((!helpers.isNumber(fixInfo.editColumn) ||
663
- (fixInfo.editColumn < 1) ||
664
- (fixInfo.editColumn >
665
- lines[effectiveLineNumber - 1].length + 1))) {
666
- throwError("fixInfo.editColumn");
667
- }
668
- cleanFixInfo.editColumn = fixInfo.editColumn;
669
- }
670
- if (fixInfo.deleteCount !== undefined) {
671
- if ((!helpers.isNumber(fixInfo.deleteCount) ||
672
- (fixInfo.deleteCount < -1) ||
673
- (fixInfo.deleteCount >
674
- lines[effectiveLineNumber - 1].length))) {
675
- throwError("fixInfo.deleteCount");
676
- }
677
- cleanFixInfo.deleteCount = fixInfo.deleteCount;
678
- }
679
- if (fixInfo.insertText !== undefined) {
680
- if (!helpers.isString(fixInfo.insertText)) {
681
- throwError("fixInfo.insertText");
682
- }
683
- cleanFixInfo.insertText = fixInfo.insertText;
684
- }
685
- }
686
- const information = errorInfo.information || rule.information;
687
- results.push({
688
- lineNumber,
689
- "ruleName": rule.names[0],
690
- "ruleNames": rule.names,
691
- "ruleDescription": rule.description,
692
- "ruleInformation": information ? information.href : null,
693
- "errorDetail": errorInfo.detail || null,
694
- "errorContext": errorInfo.context || null,
695
- "errorRange": errorInfo.range ? [ ...errorInfo.range ] : null,
696
- "fixInfo": fixInfo ? cleanFixInfo : null
697
- });
698
- }
699
- // Call (possibly external) rule function to report errors
700
- const catchCallsOnError = (error) => onError({
701
- "lineNumber": 1,
702
- "detail": `This rule threw an exception: ${error.message || error}`
703
- });
704
- const invokeRuleFunction = () => rule.function(params, onError);
705
- if (rule.asynchronous) {
706
- // Asynchronous rule, ensure it returns a Promise
707
- const ruleFunctionPromise =
708
- Promise.resolve().then(invokeRuleFunction);
709
- return handleRuleFailures ?
710
- ruleFunctionPromise.catch(catchCallsOnError) :
711
- ruleFunctionPromise;
712
- }
713
- // Synchronous rule
714
- try {
715
- invokeRuleFunction();
716
- } catch (error) {
717
- if (handleRuleFailures) {
718
- catchCallsOnError(error);
719
- } else {
720
- throw error;
721
- }
722
- }
723
- return null;
724
- }
725
- // eslint-disable-next-line jsdoc/require-jsdoc
726
- function formatResults() {
727
- // Sort results by rule name by line number
728
- results.sort((a, b) => (
729
- a.ruleName.localeCompare(b.ruleName) ||
730
- a.lineNumber - b.lineNumber
731
- ));
732
- if (resultVersion < 3) {
733
- // Remove fixInfo and multiple errors for the same rule and line number
734
- const noPrevious = {
735
- "ruleName": null,
736
- "lineNumber": -1
737
- };
738
- results = results.filter((error, index, array) => {
739
- delete error.fixInfo;
740
- const previous = array[index - 1] || noPrevious;
741
- return (
742
- (error.ruleName !== previous.ruleName) ||
743
- (error.lineNumber !== previous.lineNumber)
744
- );
745
- });
746
- }
747
- if (resultVersion === 0) {
748
- // Return a dictionary of rule->[line numbers]
749
- const dictionary = {};
750
- for (const error of results) {
751
- const ruleLines = dictionary[error.ruleName] || [];
752
- ruleLines.push(error.lineNumber);
753
- dictionary[error.ruleName] = ruleLines;
754
- }
755
- // @ts-ignore
756
- results = dictionary;
757
- } else if (resultVersion === 1) {
758
- // Use ruleAlias instead of ruleNames
759
- for (const error of results) {
760
- error.ruleAlias = error.ruleNames[1] || error.ruleName;
761
- delete error.ruleNames;
762
- }
763
- } else {
764
- // resultVersion 2 or 3: Remove unwanted ruleName
765
- for (const error of results) {
766
- delete error.ruleName;
767
- }
768
- }
769
- return results;
770
- }
771
- // Run all rules
772
- const ruleListAsync = ruleList.filter((rule) => rule.asynchronous);
773
- const ruleListSync = ruleList.filter((rule) => !rule.asynchronous);
774
- const ruleListAsyncFirst = [
775
- ...ruleListAsync,
776
- ...ruleListSync
777
- ];
778
- const callbackSuccess = () => callback(null, formatResults());
779
- const callbackError =
780
- (error) => callback(error instanceof Error ? error : new Error(error));
781
- try {
782
- const ruleResults = ruleListAsyncFirst.map(forRule);
783
- if (ruleListAsync.length > 0) {
784
- Promise.all(ruleResults.slice(0, ruleListAsync.length))
785
- .then(callbackSuccess)
786
- .catch(callbackError);
787
- } else {
788
- callbackSuccess();
789
- }
790
- } catch (error) {
791
- callbackError(error);
792
- } finally {
793
- cache.clear();
794
- }
795
- }
796
-
797
- /**
798
- * Lints a file containing Markdown content.
799
- *
800
- * @param {Rule[]} ruleList List of rules.
801
- * @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
802
- * names.
803
- * @param {string} file Path of file to lint.
804
- * @param {Object} md Instance of markdown-it.
805
- * @param {Configuration} config Configuration object.
806
- * @param {ConfigurationParser[] | null} configParsers Configuration parsers.
807
- * @param {RegExp | null} frontMatter Regular expression for front matter.
808
- * @param {boolean} handleRuleFailures Whether to handle exceptions in rules.
809
- * @param {boolean} noInlineConfig Whether to allow inline configuration.
810
- * @param {number} resultVersion Version of the LintResults object to return.
811
- * @param {Object} fs File system implementation.
812
- * @param {boolean} synchronous Whether to execute synchronously.
813
- * @param {LintContentCallback} callback Callback (err, result) function.
814
- * @returns {void}
815
- */
816
- function lintFile(
817
- ruleList,
818
- aliasToRuleNames,
819
- file,
820
- md,
821
- config,
822
- configParsers,
823
- frontMatter,
824
- handleRuleFailures,
825
- noInlineConfig,
826
- resultVersion,
827
- fs,
828
- synchronous,
829
- callback) {
830
- // eslint-disable-next-line jsdoc/require-jsdoc
831
- function lintContentWrapper(err, content) {
832
- if (err) {
833
- return callback(err);
834
- }
835
- return lintContent(
836
- ruleList,
837
- aliasToRuleNames,
838
- file,
839
- content,
840
- md,
841
- config,
842
- configParsers,
843
- frontMatter,
844
- handleRuleFailures,
845
- noInlineConfig,
846
- resultVersion,
847
- callback
848
- );
849
- }
850
- // Make a/synchronous call to read file
851
- if (synchronous) {
852
- lintContentWrapper(null, fs.readFileSync(file, "utf8"));
853
- } else {
854
- fs.readFile(file, "utf8", lintContentWrapper);
855
- }
856
- }
857
-
858
- /**
859
- * Lint files and strings specified in the Options object.
860
- *
861
- * @param {Options | null} options Options object.
862
- * @param {boolean} synchronous Whether to execute synchronously.
863
- * @param {LintCallback} callback Callback (err, result) function.
864
- * @returns {void}
865
- */
866
- function lintInput(options, synchronous, callback) {
867
- // Normalize inputs
868
- options = options || {};
869
- callback = callback || function noop() {};
870
- const customRuleList =
871
- [ options.customRules || [] ]
872
- .flat()
873
- .map((rule) => ({
874
- "names": helpers.cloneIfArray(rule.names),
875
- "description": rule.description,
876
- "information": helpers.cloneIfUrl(rule.information),
877
- "tags": helpers.cloneIfArray(rule.tags),
878
- "asynchronous": rule.asynchronous,
879
- "function": rule.function
880
- }));
881
- // eslint-disable-next-line unicorn/prefer-spread
882
- const ruleList = rules.concat(customRuleList);
883
- const ruleErr = validateRuleList(ruleList, synchronous);
884
- if (ruleErr) {
885
- callback(ruleErr);
886
- return;
887
- }
888
- let files = [];
889
- if (Array.isArray(options.files)) {
890
- files = [ ...options.files ];
891
- } else if (options.files) {
892
- files = [ String(options.files) ];
893
- }
894
- const strings = options.strings || {};
895
- const stringsKeys = Object.keys(strings);
896
- const config = options.config || { "default": true };
897
- const configParsers = options.configParsers || null;
898
- const frontMatter = (options.frontMatter === undefined) ?
899
- helpers.frontMatterRe : options.frontMatter;
900
- const handleRuleFailures = !!options.handleRuleFailures;
901
- const noInlineConfig = !!options.noInlineConfig;
902
- const resultVersion = (options.resultVersion === undefined) ?
903
- 3 : options.resultVersion;
904
- const md = markdownit({ "html": true });
905
- const markdownItPlugins = options.markdownItPlugins || [];
906
- for (const plugin of markdownItPlugins) {
907
- // @ts-ignore
908
- md.use(...plugin);
909
- }
910
- const fs = options.fs || require("node:fs");
911
- const aliasToRuleNames = mapAliasToRuleNames(ruleList);
912
- const results = newResults(ruleList);
913
- let done = false;
914
- let concurrency = 0;
915
- // eslint-disable-next-line jsdoc/require-jsdoc
916
- function lintWorker() {
917
- let currentItem = null;
918
- // eslint-disable-next-line jsdoc/require-jsdoc
919
- function lintWorkerCallback(err, result) {
920
- concurrency--;
921
- if (err) {
922
- done = true;
923
- return callback(err);
924
- }
925
- results[currentItem] = result;
926
- if (!synchronous) {
927
- lintWorker();
928
- }
929
- return null;
930
- }
931
- if (done) {
932
- // Abort for error or nothing left to do
933
- } else if (files.length > 0) {
934
- // Lint next file
935
- concurrency++;
936
- currentItem = files.shift();
937
- lintFile(
938
- ruleList,
939
- aliasToRuleNames,
940
- currentItem,
941
- md,
942
- config,
943
- configParsers,
944
- frontMatter,
945
- handleRuleFailures,
946
- noInlineConfig,
947
- resultVersion,
948
- fs,
949
- synchronous,
950
- lintWorkerCallback
951
- );
952
- } else if ((currentItem = stringsKeys.shift())) {
953
- // Lint next string
954
- concurrency++;
955
- lintContent(
956
- ruleList,
957
- aliasToRuleNames,
958
- currentItem,
959
- strings[currentItem] || "",
960
- md,
961
- config,
962
- configParsers,
963
- frontMatter,
964
- handleRuleFailures,
965
- noInlineConfig,
966
- resultVersion,
967
- lintWorkerCallback
968
- );
969
- } else if (concurrency === 0) {
970
- // Finish
971
- done = true;
972
- return callback(null, results);
973
- }
974
- return null;
975
- }
976
- if (synchronous) {
977
- while (!done) {
978
- lintWorker();
979
- }
980
- } else {
981
- // Testing on a Raspberry Pi 4 Model B with an artificial 5ms file access
982
- // delay suggests that a concurrency factor of 8 can eliminate the impact
983
- // of that delay (i.e., total time is the same as with no delay).
984
- lintWorker();
985
- lintWorker();
986
- lintWorker();
987
- lintWorker();
988
- lintWorker();
989
- lintWorker();
990
- lintWorker();
991
- lintWorker();
992
- }
993
- }
994
-
995
- /**
996
- * Lint specified Markdown files.
997
- *
998
- * @param {Options | null} options Configuration options.
999
- * @param {LintCallback} callback Callback (err, result) function.
1000
- * @returns {void}
1001
- */
1002
- function markdownlint(options, callback) {
1003
- return lintInput(options, false, callback);
1004
- }
1005
-
1006
- const markdownlintPromisify = promisify && promisify(markdownlint);
1007
-
1008
- /**
1009
- * Lint specified Markdown files.
1010
- *
1011
- * @param {Options} options Configuration options.
1012
- * @returns {Promise<LintResults>} Results object.
1013
- */
1014
- function markdownlintPromise(options) {
1015
- // @ts-ignore
1016
- return markdownlintPromisify(options);
1017
- }
1018
-
1019
- /**
1020
- * Lint specified Markdown files synchronously.
1021
- *
1022
- * @param {Options | null} options Configuration options.
1023
- * @returns {LintResults} Results object.
1024
- */
1025
- function markdownlintSync(options) {
1026
- let results = null;
1027
- lintInput(options, true, function callback(error, res) {
1028
- if (error) {
1029
- throw error;
1030
- }
1031
- results = res;
1032
- });
1033
- // @ts-ignore
1034
- return results;
1035
- }
1036
-
1037
- /**
1038
- * Resolve referenced "extends" path in a configuration file
1039
- * using path.resolve() with require.resolve() as a fallback.
1040
- *
1041
- * @param {string} configFile Configuration file name.
1042
- * @param {string} referenceId Referenced identifier to resolve.
1043
- * @param {Object} fs File system implementation.
1044
- * @param {ResolveConfigExtendsCallback} callback Callback (err, result)
1045
- * function.
1046
- * @returns {void}
1047
- */
1048
- function resolveConfigExtends(configFile, referenceId, fs, callback) {
1049
- const configFileDirname = path.dirname(configFile);
1050
- const resolvedExtendsFile = path.resolve(configFileDirname, referenceId);
1051
- fs.access(resolvedExtendsFile, (err) => {
1052
- if (err) {
1053
- // Not a file, try require.resolve
1054
- try {
1055
- return callback(null, dynamicRequire.resolve(
1056
- referenceId,
1057
- { "paths": [ configFileDirname ] }
1058
- ));
1059
- } catch {
1060
- // Unable to resolve, use resolvedExtendsFile
1061
- }
1062
- }
1063
- return callback(null, resolvedExtendsFile);
1064
- });
1065
- }
1066
-
1067
- /**
1068
- * Resolve referenced "extends" path in a configuration file
1069
- * using path.resolve() with require.resolve() as a fallback.
1070
- *
1071
- * @param {string} configFile Configuration file name.
1072
- * @param {string} referenceId Referenced identifier to resolve.
1073
- * @param {Object} fs File system implementation.
1074
- * @returns {string} Resolved path to file.
1075
- */
1076
- function resolveConfigExtendsSync(configFile, referenceId, fs) {
1077
- const configFileDirname = path.dirname(configFile);
1078
- const resolvedExtendsFile = path.resolve(configFileDirname, referenceId);
1079
- try {
1080
- fs.accessSync(resolvedExtendsFile);
1081
- return resolvedExtendsFile;
1082
- } catch {
1083
- // Not a file, try require.resolve
1084
- }
1085
- try {
1086
- return dynamicRequire.resolve(
1087
- referenceId,
1088
- { "paths": [ configFileDirname ] }
1089
- );
1090
- } catch {
1091
- // Unable to resolve, return resolvedExtendsFile
1092
- }
1093
- return resolvedExtendsFile;
1094
- }
1095
-
1096
- /**
1097
- * Extend specified configuration object.
1098
- *
1099
- * @param {Configuration} config Configuration object.
1100
- * @param {string} file Configuration file name.
1101
- * @param {ConfigurationParser[]} parsers Parsing
1102
- * function(s).
1103
- * @param {Object} fs File system implementation.
1104
- * @param {ReadConfigCallback} callback Callback (err, result) function.
1105
- * @returns {void}
1106
- */
1107
- function extendConfig(config, file, parsers, fs, callback) {
1108
- const configExtends = config.extends;
1109
- if (configExtends) {
1110
- return resolveConfigExtends(
1111
- file,
1112
- helpers.expandTildePath(configExtends, require("node:os")),
1113
- fs,
1114
- // eslint-disable-next-line no-use-before-define
1115
- (_, resolvedExtends) => readConfig(
1116
- // @ts-ignore
1117
- resolvedExtends,
1118
- parsers,
1119
- fs,
1120
- (err, extendsConfig) => {
1121
- if (err) {
1122
- return callback(err);
1123
- }
1124
- const result = {
1125
- ...extendsConfig,
1126
- ...config
1127
- };
1128
- delete result.extends;
1129
- return callback(null, result);
1130
- }
1131
- )
1132
- );
1133
- }
1134
- return callback(null, config);
1135
- }
1136
-
1137
- const extendConfigPromisify = promisify && promisify(extendConfig);
1138
-
1139
- /**
1140
- * Extend specified configuration object.
1141
- *
1142
- * @param {Configuration} config Configuration object.
1143
- * @param {string} file Configuration file name.
1144
- * @param {ConfigurationParser[]} [parsers] Parsing function(s).
1145
- * @param {Object} [fs] File system implementation.
1146
- * @returns {Promise<Configuration>} Configuration object.
1147
- */
1148
- function extendConfigPromise(config, file, parsers, fs) {
1149
- // @ts-ignore
1150
- return extendConfigPromisify(config, file, parsers, fs);
1151
- }
1152
-
1153
- /**
1154
- * Read specified configuration file.
1155
- *
1156
- * @param {string} file Configuration file name.
1157
- * @param {ConfigurationParser[] | ReadConfigCallback} parsers Parsing
1158
- * function(s).
1159
- * @param {Object} [fs] File system implementation.
1160
- * @param {ReadConfigCallback} [callback] Callback (err, result) function.
1161
- * @returns {void}
1162
- */
1163
- function readConfig(file, parsers, fs, callback) {
1164
- if (!callback) {
1165
- if (fs) {
1166
- callback = fs;
1167
- fs = null;
1168
- } else {
1169
- // @ts-ignore
1170
- callback = parsers;
1171
- // @ts-ignore
1172
- parsers = null;
1173
- }
1174
- }
1175
- if (!fs) {
1176
- fs = require("node:fs");
1177
- }
1178
- // Read file
1179
- file = helpers.expandTildePath(file, require("node:os"));
1180
- // eslint-disable-next-line n/prefer-promises/fs
1181
- fs.readFile(file, "utf8", (err, content) => {
1182
- if (err) {
1183
- // @ts-ignore
1184
- return callback(err);
1185
- }
1186
- // Try to parse file
1187
- // @ts-ignore
1188
- const { config, message } = parseConfiguration(file, content, parsers);
1189
- if (!config) {
1190
- // @ts-ignore
1191
- return callback(new Error(message));
1192
- }
1193
- // Extend configuration
1194
- // @ts-ignore
1195
- return extendConfig(config, file, parsers, fs, callback);
1196
- });
1197
- }
1198
-
1199
- const readConfigPromisify = promisify && promisify(readConfig);
1200
-
1201
- /**
1202
- * Read specified configuration file.
1203
- *
1204
- * @param {string} file Configuration file name.
1205
- * @param {ConfigurationParser[]} [parsers] Parsing function(s).
1206
- * @param {Object} [fs] File system implementation.
1207
- * @returns {Promise<Configuration>} Configuration object.
1208
- */
1209
- function readConfigPromise(file, parsers, fs) {
1210
- // @ts-ignore
1211
- return readConfigPromisify(file, parsers, fs);
1212
- }
1213
-
1214
- /**
1215
- * Read specified configuration file synchronously.
1216
- *
1217
- * @param {string} file Configuration file name.
1218
- * @param {ConfigurationParser[]} [parsers] Parsing function(s).
1219
- * @param {Object} [fs] File system implementation.
1220
- * @returns {Configuration} Configuration object.
1221
- * @throws An Error if processing fails.
1222
- */
1223
- function readConfigSync(file, parsers, fs) {
1224
- if (!fs) {
1225
- fs = require("node:fs");
1226
- }
1227
- // Read file
1228
- const os = require("node:os");
1229
- file = helpers.expandTildePath(file, os);
1230
- const content = fs.readFileSync(file, "utf8");
1231
- // Try to parse file
1232
- const { config, message } = parseConfiguration(file, content, parsers);
1233
- if (!config) {
1234
- throw new Error(message);
1235
- }
1236
- // Extend configuration
1237
- const configExtends = config.extends;
1238
- if (configExtends) {
1239
- delete config.extends;
1240
- const resolvedExtends = resolveConfigExtendsSync(
1241
- file,
1242
- helpers.expandTildePath(configExtends, os),
1243
- fs
1244
- );
1245
- return {
1246
- ...readConfigSync(resolvedExtends, parsers, fs),
1247
- ...config
1248
- };
1249
- }
1250
- return config;
1251
- }
1252
-
1253
- /**
1254
- * Gets the (semantic) version of the library.
1255
- *
1256
- * @returns {string} SemVer string.
1257
- */
1258
- function getVersion() {
1259
- return require("./constants").version;
1260
- }
1261
-
1262
- // Export a/synchronous/Promise APIs
1263
- markdownlint.sync = markdownlintSync;
1264
- markdownlint.readConfig = readConfig;
1265
- markdownlint.readConfigSync = readConfigSync;
1266
- markdownlint.getVersion = getVersion;
1267
- markdownlint.promises = {
1268
- "markdownlint": markdownlintPromise,
1269
- "extendConfig": extendConfigPromise,
1270
- "readConfig": readConfigPromise
1271
- };
1272
- module.exports = markdownlint;
1273
-
1274
- // Type declarations
1275
-
1276
- /**
1277
- * Function to implement rule logic.
1278
- *
1279
- * @callback RuleFunction
1280
- * @param {RuleParams} params Rule parameters.
1281
- * @param {RuleOnError} onError Error-reporting callback.
1282
- * @returns {void}
1283
- */
1284
-
1285
- /**
1286
- * Rule parameters.
1287
- *
1288
- * @typedef {Object} RuleParams
1289
- * @property {string} name File/string name.
1290
- * @property {MarkdownItToken[]} tokens Token objects from markdown-it.
1291
- * @property {string[]} lines File/string lines.
1292
- * @property {string[]} frontMatterLines Front matter lines.
1293
- * @property {RuleConfiguration} config Rule configuration.
1294
- */
1295
-
1296
- /**
1297
- * Markdown-It token.
1298
- *
1299
- * @typedef {Object} MarkdownItToken
1300
- * @property {string[][]} attrs HTML attributes.
1301
- * @property {boolean} block Block-level token.
1302
- * @property {MarkdownItToken[]} children Child nodes.
1303
- * @property {string} content Tag contents.
1304
- * @property {boolean} hidden Ignore element.
1305
- * @property {string} info Fence info.
1306
- * @property {number} level Nesting level.
1307
- * @property {number[]} map Beginning/ending line numbers.
1308
- * @property {string} markup Markup text.
1309
- * @property {Object} meta Arbitrary data.
1310
- * @property {number} nesting Level change.
1311
- * @property {string} tag HTML tag name.
1312
- * @property {string} type Token type.
1313
- * @property {number} lineNumber Line number (1-based).
1314
- * @property {string} line Line content.
1315
- */
1316
-
1317
- /**
1318
- * Error-reporting callback.
1319
- *
1320
- * @callback RuleOnError
1321
- * @param {RuleOnErrorInfo} onErrorInfo Error information.
1322
- * @returns {void}
1323
- */
1324
-
1325
- /**
1326
- * Fix information for RuleOnError callback.
1327
- *
1328
- * @typedef {Object} RuleOnErrorInfo
1329
- * @property {number} lineNumber Line number (1-based).
1330
- * @property {string} [detail] Detail about the error.
1331
- * @property {string} [context] Context for the error.
1332
- * @property {URL} [information] Link to more information.
1333
- * @property {number[]} [range] Column number (1-based) and length.
1334
- * @property {RuleOnErrorFixInfo} [fixInfo] Fix information.
1335
- */
1336
-
1337
- /**
1338
- * Fix information for RuleOnErrorInfo.
1339
- *
1340
- * @typedef {Object} RuleOnErrorFixInfo
1341
- * @property {number} [lineNumber] Line number (1-based).
1342
- * @property {number} [editColumn] Column of the fix (1-based).
1343
- * @property {number} [deleteCount] Count of characters to delete.
1344
- * @property {string} [insertText] Text to insert (after deleting).
1345
- */
1346
-
1347
- /**
1348
- * Rule definition.
1349
- *
1350
- * @typedef {Object} Rule
1351
- * @property {string[]} names Rule name(s).
1352
- * @property {string} description Rule description.
1353
- * @property {URL} [information] Link to more information.
1354
- * @property {string[]} tags Rule tag(s).
1355
- * @property {boolean} [asynchronous] True if asynchronous.
1356
- * @property {RuleFunction} function Rule implementation.
1357
- */
1358
-
1359
- /**
1360
- * Configuration options.
1361
- *
1362
- * @typedef {Object} Options
1363
- * @property {Configuration} [config] Configuration object.
1364
- * @property {ConfigurationParser[]} [configParsers] Configuration parsers.
1365
- * @property {Rule[] | Rule} [customRules] Custom rules.
1366
- * @property {string[] | string} [files] Files to lint.
1367
- * @property {RegExp | null} [frontMatter] Front matter pattern.
1368
- * @property {Object} [fs] File system implementation.
1369
- * @property {boolean} [handleRuleFailures] True to catch exceptions.
1370
- * @property {Plugin[]} [markdownItPlugins] Additional plugins.
1371
- * @property {boolean} [noInlineConfig] True to ignore HTML directives.
1372
- * @property {number} [resultVersion] Results object version.
1373
- * @property {Object.<string, string>} [strings] Strings to lint.
1374
- */
1375
-
1376
- /**
1377
- * A markdown-it plugin.
1378
- *
1379
- * @typedef {Array} Plugin
1380
- */
1381
-
1382
- /**
1383
- * Function to pretty-print lint results.
1384
- *
1385
- * @callback ToStringCallback
1386
- * @param {boolean} [ruleAliases] True to use rule aliases.
1387
- * @returns {string}
1388
- */
1389
-
1390
- /**
1391
- * Lint results (for resultVersion 3).
1392
- *
1393
- * @typedef {Object.<string, LintError[]>} LintResults
1394
- * @property {ToStringCallback} toString String representation.
1395
- */
1396
-
1397
- /**
1398
- * Lint error.
1399
- *
1400
- * @typedef {Object} LintError
1401
- * @property {number} lineNumber Line number (1-based).
1402
- * @property {string[]} ruleNames Rule name(s).
1403
- * @property {string} ruleDescription Rule description.
1404
- * @property {string} ruleInformation Link to more information.
1405
- * @property {string} errorDetail Detail about the error.
1406
- * @property {string} errorContext Context for the error.
1407
- * @property {number[]} errorRange Column number (1-based) and length.
1408
- * @property {FixInfo} [fixInfo] Fix information.
1409
- */
1410
-
1411
- /**
1412
- * Fix information.
1413
- *
1414
- * @typedef {Object} FixInfo
1415
- * @property {number} [lineNumber] Line number (1-based).
1416
- * @property {number} [editColumn] Column of the fix (1-based).
1417
- * @property {number} [deleteCount] Count of characters to delete.
1418
- * @property {string} [insertText] Text to insert (after deleting).
1419
- */
1420
-
1421
- /**
1422
- * Called with the result of linting a string or document.
1423
- *
1424
- * @callback LintContentCallback
1425
- * @param {Error | null} error Error iff failed.
1426
- * @param {LintError[]} [result] Result iff successful.
1427
- * @returns {void}
1428
- */
1429
-
1430
- /**
1431
- * Called with the result of the lint function.
1432
- *
1433
- * @callback LintCallback
1434
- * @param {Error | null} error Error object iff failed.
1435
- * @param {LintResults} [results] Lint results iff succeeded.
1436
- * @returns {void}
1437
- */
1438
-
1439
- /**
1440
- * Configuration object for linting rules. For the JSON schema, see
1441
- * {@link ../schema/markdownlint-config-schema.json}.
1442
- *
1443
- * @typedef {import("./configuration").Configuration} Configuration
1444
- */
1445
-
1446
- /**
1447
- * Rule configuration object.
1448
- *
1449
- * @typedef {boolean | Object} RuleConfiguration Rule configuration.
1450
- */
1451
-
1452
- /**
1453
- * Parses a configuration string and returns a configuration object.
1454
- *
1455
- * @callback ConfigurationParser
1456
- * @param {string} text Configuration string.
1457
- * @returns {Configuration}
1458
- */
1459
-
1460
- /**
1461
- * Called with the result of the readConfig function.
1462
- *
1463
- * @callback ReadConfigCallback
1464
- * @param {Error | null} err Error object or null.
1465
- * @param {Configuration} [config] Configuration object.
1466
- * @returns {void}
1467
- */
1468
-
1469
- /**
1470
- * Called with the result of the resolveConfigExtends function.
1471
- *
1472
- * @callback ResolveConfigExtendsCallback
1473
- * @param {Error | null} err Error object or null.
1474
- * @param {string} [path] Resolved path to file.
1475
- * @returns {void}
1476
- */