@alexlit/lint-kit 189.1.0 → 190.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 (177) hide show
  1. package/package.json +1 -1
  2. package/packages/config-eslint/package.json +4 -4
  3. package/packages/config-eslint/plugins/json.js +1 -1
  4. package/packages/config-eslint/plugins/prettier.js +1 -1
  5. package/packages/config-eslint/plugins/unicorn.js +2 -1
  6. package/packages/config-markdownlint/node_modules/ansi-regex/index.d.ts +33 -0
  7. package/packages/config-markdownlint/node_modules/ansi-regex/index.js +14 -0
  8. package/packages/config-markdownlint/node_modules/ansi-regex/license +9 -0
  9. package/packages/config-markdownlint/node_modules/ansi-regex/package.json +61 -0
  10. package/packages/config-markdownlint/node_modules/ansi-regex/readme.md +66 -0
  11. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +529 -0
  12. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
  13. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
  14. package/packages/config-markdownlint/node_modules/markdownlint/README.md +1112 -0
  15. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +194 -0
  16. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
  17. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
  18. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2858 -0
  19. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +51 -0
  20. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
  21. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +50 -0
  22. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
  23. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
  24. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +50 -0
  25. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +62 -0
  26. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
  27. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
  28. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +58 -0
  29. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
  30. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
  31. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
  32. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
  33. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
  34. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +67 -0
  35. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
  36. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +44 -0
  37. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
  38. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
  39. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +32 -0
  40. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +44 -0
  41. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +100 -0
  42. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
  43. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
  44. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
  45. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +33 -0
  46. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +55 -0
  47. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +44 -0
  48. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
  49. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
  50. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +52 -0
  51. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
  52. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
  53. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +64 -0
  54. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +38 -0
  55. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +87 -0
  56. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +45 -0
  57. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +48 -0
  58. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
  59. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
  60. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +42 -0
  61. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +36 -0
  62. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +35 -0
  63. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +117 -0
  64. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +52 -0
  65. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
  66. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
  67. package/packages/config-markdownlint/node_modules/markdownlint/doc/md055.md +55 -0
  68. package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +37 -0
  69. package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +48 -0
  70. package/packages/config-markdownlint/node_modules/markdownlint/doc/md059.md +33 -0
  71. package/packages/config-markdownlint/node_modules/markdownlint/doc/md060.md +130 -0
  72. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
  73. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +29 -0
  74. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.cjs +695 -0
  75. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark-helpers.cjs +332 -0
  76. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
  77. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.cjs +16 -0
  78. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.mjs +80 -0
  79. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +2417 -0
  80. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +8 -0
  81. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.mjs +14 -0
  82. package/packages/config-markdownlint/node_modules/markdownlint/lib/defer-require.cjs +18 -0
  83. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.d.mts +1 -0
  84. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-async.mjs +3 -0
  85. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.d.mts +1 -0
  86. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-promise.mjs +3 -0
  87. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.d.mts +1 -0
  88. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports-sync.mjs +3 -0
  89. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.d.mts +30 -0
  90. package/packages/config-markdownlint/node_modules/markdownlint/lib/exports.mjs +33 -0
  91. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownit.cjs +171 -0
  92. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.mts +615 -0
  93. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.mjs +1592 -0
  94. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.mjs +32 -0
  95. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.mjs +47 -0
  96. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.mjs +72 -0
  97. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.mjs +69 -0
  98. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.mjs +84 -0
  99. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.mjs +96 -0
  100. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.mjs +78 -0
  101. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.mjs +56 -0
  102. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.mjs +40 -0
  103. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.mjs +91 -0
  104. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.mjs +47 -0
  105. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.mjs +43 -0
  106. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.mjs +77 -0
  107. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.mjs +68 -0
  108. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.mjs +103 -0
  109. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.mjs +37 -0
  110. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.mjs +45 -0
  111. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.mjs +45 -0
  112. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.mjs +46 -0
  113. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.mjs +50 -0
  114. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.mjs +39 -0
  115. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.mjs +84 -0
  116. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.mjs +57 -0
  117. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.mjs +61 -0
  118. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.mjs +78 -0
  119. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.mjs +46 -0
  120. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.mjs +92 -0
  121. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.mjs +23 -0
  122. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.mjs +55 -0
  123. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.mjs +94 -0
  124. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.mjs +73 -0
  125. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.mjs +59 -0
  126. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.mjs +32 -0
  127. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.mjs +71 -0
  128. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.mjs +58 -0
  129. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.mjs +72 -0
  130. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.mjs +110 -0
  131. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.mjs +61 -0
  132. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.mjs +31 -0
  133. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.mjs +28 -0
  134. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.mjs +47 -0
  135. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.mjs +115 -0
  136. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.mjs +173 -0
  137. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.mjs +40 -0
  138. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.mjs +60 -0
  139. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.mjs +122 -0
  140. package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.mjs +72 -0
  141. package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.mjs +50 -0
  142. package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.mjs +57 -0
  143. package/packages/config-markdownlint/node_modules/markdownlint/lib/md059.mjs +71 -0
  144. package/packages/config-markdownlint/node_modules/markdownlint/lib/md060.mjs +209 -0
  145. package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-parse.mjs +337 -0
  146. package/packages/config-markdownlint/node_modules/markdownlint/lib/micromark-types.d.mts +11 -0
  147. package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-browser.mjs +22 -0
  148. package/packages/config-markdownlint/node_modules/markdownlint/lib/node-imports-node.mjs +11 -0
  149. package/packages/config-markdownlint/node_modules/markdownlint/lib/parse-configuration.mjs +47 -0
  150. package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.cjs +52 -0
  151. package/packages/config-markdownlint/node_modules/markdownlint/lib/resolve-module.d.cts +34 -0
  152. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.mjs +122 -0
  153. package/packages/config-markdownlint/node_modules/markdownlint/lib/types.d.mts +13 -0
  154. package/packages/config-markdownlint/node_modules/markdownlint/package.json +120 -0
  155. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +349 -0
  156. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +310 -0
  157. package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +26 -0
  158. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +5138 -0
  159. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +5143 -0
  160. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
  161. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
  162. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +27 -0
  163. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
  164. package/packages/config-markdownlint/node_modules/string-width/index.d.ts +39 -0
  165. package/packages/config-markdownlint/node_modules/string-width/index.js +203 -0
  166. package/packages/config-markdownlint/node_modules/string-width/license +9 -0
  167. package/packages/config-markdownlint/node_modules/string-width/package.json +65 -0
  168. package/packages/config-markdownlint/node_modules/string-width/readme.md +66 -0
  169. package/packages/config-markdownlint/node_modules/strip-ansi/index.d.ts +15 -0
  170. package/packages/config-markdownlint/node_modules/strip-ansi/index.js +19 -0
  171. package/packages/config-markdownlint/node_modules/strip-ansi/license +9 -0
  172. package/packages/config-markdownlint/node_modules/strip-ansi/package.json +59 -0
  173. package/packages/config-markdownlint/node_modules/strip-ansi/readme.md +37 -0
  174. package/packages/config-markdownlint/package.json +2 -2
  175. package/packages/config-stylelint/package.json +2 -2
  176. package/packages/config-stylelint/plugins/scss.js +1 -1
  177. package/packages/config-stylelint/plugins/selector-no-empty.js +1 -1
@@ -0,0 +1,695 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const micromark = require("./micromark-helpers.cjs");
6
+
7
+ const { newlineRe, nextLinesRe } = require("./shared.cjs");
8
+
9
+ module.exports.newLineRe = newlineRe;
10
+ module.exports.nextLinesRe = nextLinesRe;
11
+
12
+ /** @typedef {import("../lib/exports.mjs").RuleOnError} RuleOnError */
13
+ /** @typedef {import("../lib/exports.mjs").RuleOnErrorFixInfo} RuleOnErrorFixInfo */
14
+ /** @typedef {import("../lib/exports.mjs").MicromarkToken} MicromarkToken */
15
+ // eslint-disable-next-line jsdoc/valid-types
16
+ /** @typedef {import("micromark-extension-gfm-footnote", { with: { "resolution-mode": "import" } })} */
17
+ // eslint-disable-next-line jsdoc/valid-types
18
+ /** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
19
+
20
+ // Regular expression for matching common front matter (YAML and TOML)
21
+ // @ts-ignore
22
+ module.exports.frontMatterRe =
23
+ /((^---[^\S\r\n\u2028\u2029]*$[\s\S]+?^---\s*)|(^\+\+\+[^\S\r\n\u2028\u2029]*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{[^\S\r\n\u2028\u2029]*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m;
24
+
25
+ // Regular expression for matching the start of inline disable/enable comments
26
+ const inlineCommentStartRe =
27
+ /(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
28
+ module.exports.inlineCommentStartRe = inlineCommentStartRe;
29
+
30
+ // Regular expression for identifying an HTML entity at the end of a line
31
+ module.exports.endOfLineHtmlEntityRe =
32
+ /&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
33
+
34
+ // Regular expression for identifying a GitHub emoji code at the end of a line
35
+ module.exports.endOfLineGemojiCodeRe =
36
+ /:(?:[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})+):$/;
37
+
38
+ // All punctuation characters (normal and full-width)
39
+ const allPunctuation = ".,;:!?。,;:!?";
40
+ module.exports.allPunctuation = allPunctuation;
41
+
42
+ // All punctuation characters without question mark (normal and full-width)
43
+ module.exports.allPunctuationNoQuestion = allPunctuation.replace(/[??]/gu, "");
44
+
45
+ /**
46
+ * Returns true iff the input is a Number.
47
+ *
48
+ * @param {Object} obj Object of unknown type.
49
+ * @returns {boolean} True iff obj is a Number.
50
+ */
51
+ function isNumber(obj) {
52
+ return typeof obj === "number";
53
+ }
54
+ module.exports.isNumber = isNumber;
55
+
56
+ /**
57
+ * Returns true iff the input is a String.
58
+ *
59
+ * @param {Object} obj Object of unknown type.
60
+ * @returns {boolean} True iff obj is a String.
61
+ */
62
+ function isString(obj) {
63
+ return typeof obj === "string";
64
+ }
65
+ module.exports.isString = isString;
66
+
67
+ /**
68
+ * Returns true iff the input String is empty.
69
+ *
70
+ * @param {string} str String of unknown length.
71
+ * @returns {boolean} True iff the input String is empty.
72
+ */
73
+ function isEmptyString(str) {
74
+ return str.length === 0;
75
+ }
76
+ module.exports.isEmptyString = isEmptyString;
77
+
78
+ /**
79
+ * Returns true iff the input is an Object.
80
+ *
81
+ * @param {Object} obj Object of unknown type.
82
+ * @returns {boolean} True iff obj is an Object.
83
+ */
84
+ function isObject(obj) {
85
+ return !!obj && (typeof obj === "object") && !Array.isArray(obj);
86
+ }
87
+ module.exports.isObject = isObject;
88
+
89
+ /**
90
+ * Returns true iff the input is a URL.
91
+ *
92
+ * @param {Object} obj Object of unknown type.
93
+ * @returns {boolean} True iff obj is a URL.
94
+ */
95
+ function isUrl(obj) {
96
+ return !!obj && (Object.getPrototypeOf(obj) === URL.prototype);
97
+ }
98
+ module.exports.isUrl = isUrl;
99
+
100
+ /**
101
+ * Clones the input if it is an Array.
102
+ *
103
+ * @param {Object} arr Object of unknown type.
104
+ * @returns {Object} Clone of obj iff obj is an Array.
105
+ */
106
+ function cloneIfArray(arr) {
107
+ return Array.isArray(arr) ? [ ...arr ] : arr;
108
+ }
109
+ module.exports.cloneIfArray = cloneIfArray;
110
+
111
+ /**
112
+ * Clones the input if it is a URL.
113
+ *
114
+ * @param {Object | undefined} url Object of unknown type.
115
+ * @returns {Object} Clone of obj iff obj is a URL.
116
+ */
117
+ function cloneIfUrl(url) {
118
+ // @ts-ignore
119
+ return isUrl(url) ? new URL(url) : url;
120
+ }
121
+ module.exports.cloneIfUrl = cloneIfUrl;
122
+
123
+ /**
124
+ * Gets a Regular Expression for matching the specified HTML attribute.
125
+ *
126
+ * @param {string} name HTML attribute name.
127
+ * @returns {RegExp} Regular Expression for matching.
128
+ */
129
+ module.exports.getHtmlAttributeRe = function getHtmlAttributeRe(name) {
130
+ return new RegExp(`\\s${name}\\s*=\\s*['"]?([^'"\\s>]*)`, "iu");
131
+ };
132
+
133
+ /**
134
+ * Returns true iff the input line is blank (contains nothing, whitespace, or
135
+ * comments (unclosed start/end comments allowed)).
136
+ *
137
+ * @param {string} line Input line.
138
+ * @returns {boolean} True iff line is blank.
139
+ */
140
+ function isBlankLine(line) {
141
+ const startComment = "<!--";
142
+ const endComment = "-->";
143
+ const removeComments = (/** @type {string} */ s) => {
144
+ while (true) {
145
+ const start = s.indexOf(startComment);
146
+ const end = s.indexOf(endComment);
147
+ if ((end !== -1) && ((start === -1) || (end < start))) {
148
+ // Unmatched end comment is first
149
+ s = s.slice(end + endComment.length);
150
+ } else if ((start !== -1) && (end !== -1)) {
151
+ // Start comment is before end comment
152
+ s = s.slice(0, start) + s.slice(end + endComment.length);
153
+ } else if ((start !== -1) && (end === -1)) {
154
+ // Unmatched start comment is last
155
+ s = s.slice(0, start);
156
+ } else {
157
+ // No more comments to remove
158
+ return s;
159
+ }
160
+ }
161
+ };
162
+ return (
163
+ !line ||
164
+ !line.trim() ||
165
+ !removeComments(line).replace(/>/g, "").trim()
166
+ );
167
+ }
168
+ module.exports.isBlankLine = isBlankLine;
169
+
170
+ // Replaces the content of properly-formatted CommonMark comments with "."
171
+ // This preserves the line/column information for the rest of the document
172
+ // https://spec.commonmark.org/0.29/#html-blocks
173
+ // https://spec.commonmark.org/0.29/#html-comment
174
+ const htmlCommentBegin = "<!--";
175
+ const htmlCommentEnd = "-->";
176
+ const safeCommentCharacter = ".";
177
+ const startsWithPipeRe = /^ *\|/;
178
+ const notCrLfRe = /[^\r\n]/g;
179
+ const notSpaceCrLfRe = /[^ \r\n]/g;
180
+ const trailingSpaceRe = / +[\r\n]/g;
181
+ const replaceTrailingSpace = (/** @type {string} */ s) => s.replace(notCrLfRe, safeCommentCharacter);
182
+ module.exports.clearHtmlCommentText = function clearHtmlCommentText(/** @type {string} */ text) {
183
+ let i = 0;
184
+ while ((i = text.indexOf(htmlCommentBegin, i)) !== -1) {
185
+ const j = text.indexOf(htmlCommentEnd, i + 2);
186
+ if (j === -1) {
187
+ // Un-terminated comments are treated as text
188
+ break;
189
+ }
190
+ // If the comment has content...
191
+ if (j > i + htmlCommentBegin.length) {
192
+ const content = text.slice(i + htmlCommentBegin.length, j);
193
+ const lastLf = text.lastIndexOf("\n", i) + 1;
194
+ const preText = text.slice(lastLf, i);
195
+ const isBlock = preText.trim().length === 0;
196
+ const couldBeTable = startsWithPipeRe.test(preText);
197
+ const spansTableCells = couldBeTable && content.includes("\n");
198
+ const isValid =
199
+ isBlock ||
200
+ !(
201
+ spansTableCells ||
202
+ content.startsWith(">") ||
203
+ content.startsWith("->") ||
204
+ content.endsWith("-") ||
205
+ content.includes("--")
206
+ );
207
+ // If a valid block/inline comment...
208
+ if (isValid) {
209
+ const clearedContent = content
210
+ .replace(notSpaceCrLfRe, safeCommentCharacter)
211
+ .replace(trailingSpaceRe, replaceTrailingSpace);
212
+ text =
213
+ text.slice(0, i + htmlCommentBegin.length) +
214
+ clearedContent +
215
+ text.slice(j);
216
+ }
217
+ }
218
+ i = j + htmlCommentEnd.length;
219
+ }
220
+ return text;
221
+ };
222
+
223
+ // Escapes a string for use in a RegExp
224
+ module.exports.escapeForRegExp = function escapeForRegExp(/** @type {string} */ str) {
225
+ return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
226
+ };
227
+
228
+ /**
229
+ * Adds ellipsis to the left/right/middle of the specified text.
230
+ *
231
+ * @param {string} text Text to ellipsify.
232
+ * @param {boolean} [start] True iff the start of the text is important.
233
+ * @param {boolean} [end] True iff the end of the text is important.
234
+ * @returns {string} Ellipsified text.
235
+ */
236
+ function ellipsify(text, start, end) {
237
+ if (text.length <= 30) {
238
+ // Nothing to do
239
+ } else if (start && end) {
240
+ text = text.slice(0, 15) + "..." + text.slice(-15);
241
+ } else if (end) {
242
+ text = "..." + text.slice(-30);
243
+ } else {
244
+ text = text.slice(0, 30) + "...";
245
+ }
246
+ return text;
247
+ }
248
+ module.exports.ellipsify = ellipsify;
249
+
250
+ /**
251
+ * Adds a generic error object via the onError callback.
252
+ *
253
+ * @param {RuleOnError} onError RuleOnError instance.
254
+ * @param {number} lineNumber Line number.
255
+ * @param {string} [detail] Error details.
256
+ * @param {string} [context] Error context.
257
+ * @param {number[]} [range] Column and length of error.
258
+ * @param {RuleOnErrorFixInfo} [fixInfo] RuleOnErrorFixInfo instance.
259
+ * @returns {void}
260
+ */
261
+ function addError(onError, lineNumber, detail, context, range, fixInfo) {
262
+ onError({
263
+ lineNumber,
264
+ detail,
265
+ context,
266
+ range,
267
+ fixInfo
268
+ });
269
+ }
270
+ module.exports.addError = addError;
271
+
272
+ /**
273
+ * Adds an error object with details conditionally via the onError callback.
274
+ *
275
+ * @param {RuleOnError} onError RuleOnError instance.
276
+ * @param {number} lineNumber Line number.
277
+ * @param {Object} expected Expected value.
278
+ * @param {Object} actual Actual value.
279
+ * @param {string} [detail] Error details.
280
+ * @param {string} [context] Error context.
281
+ * @param {number[]} [range] Column and length of error.
282
+ * @param {RuleOnErrorFixInfo} [fixInfo] RuleOnErrorFixInfo instance.
283
+ * @returns {void}
284
+ */
285
+ function addErrorDetailIf(
286
+ onError, lineNumber, expected, actual, detail, context, range, fixInfo) {
287
+ if (expected !== actual) {
288
+ addError(
289
+ onError,
290
+ lineNumber,
291
+ "Expected: " + expected + "; Actual: " + actual +
292
+ (detail ? "; " + detail : ""),
293
+ context,
294
+ range,
295
+ fixInfo);
296
+ }
297
+ }
298
+ module.exports.addErrorDetailIf = addErrorDetailIf;
299
+
300
+ /**
301
+ * Adds an error object with context via the onError callback.
302
+ *
303
+ * @param {RuleOnError} onError RuleOnError instance.
304
+ * @param {number} lineNumber Line number.
305
+ * @param {string} context Error context.
306
+ * @param {boolean} [start] True iff the start of the text is important.
307
+ * @param {boolean} [end] True iff the end of the text is important.
308
+ * @param {number[]} [range] Column and length of error.
309
+ * @param {RuleOnErrorFixInfo} [fixInfo] RuleOnErrorFixInfo instance.
310
+ * @returns {void}
311
+ */
312
+ function addErrorContext(onError, lineNumber, context, start, end, range, fixInfo) {
313
+ // Normalize new line characters so Linux and Windows trim consistently
314
+ context = ellipsify(context.replace(newlineRe, "\n"), start, end);
315
+ addError(onError, lineNumber, undefined, context, range, fixInfo);
316
+ }
317
+ module.exports.addErrorContext = addErrorContext;
318
+
319
+ /**
320
+ * Defines a range within a file (start line/column to end line/column, subset of MicromarkToken).
321
+ *
322
+ * @typedef {Object} FileRange
323
+ * @property {number} startLine Start line (1-based).
324
+ * @property {number} startColumn Start column (1-based).
325
+ * @property {number} endLine End line (1-based).
326
+ * @property {number} endColumn End column (1-based).
327
+ */
328
+
329
+ /**
330
+ * Returns whether line/column A is less than or equal to line/column B.
331
+ *
332
+ * @param {number} lineA Line A.
333
+ * @param {number} columnA Column A.
334
+ * @param {number} lineB Line B.
335
+ * @param {number} columnB Column B.
336
+ * @returns {boolean} True iff A is less than or equal to B.
337
+ */
338
+ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => (
339
+ (lineA < lineB) ||
340
+ ((lineA === lineB) && (columnA <= columnB))
341
+ );
342
+
343
+ /**
344
+ * Returns whether two ranges (or MicromarkTokens) overlap anywhere.
345
+ *
346
+ * @param {FileRange|MicromarkToken} rangeA Range A.
347
+ * @param {FileRange|MicromarkToken} rangeB Range B.
348
+ * @returns {boolean} True iff the two ranges overlap.
349
+ */
350
+ module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {
351
+ const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn);
352
+ const first = lte ? rangeA : rangeB;
353
+ const second = lte ? rangeB : rangeA;
354
+ return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn);
355
+ };
356
+
357
+ // Determines if the front matter includes a title
358
+ module.exports.frontMatterHasTitle =
359
+ function frontMatterHasTitle(/** @type {readonly string[]} */ frontMatterLines, /** @type {string} */ frontMatterTitlePattern) {
360
+ const ignoreFrontMatter =
361
+ (frontMatterTitlePattern !== undefined) && !frontMatterTitlePattern;
362
+ const frontMatterTitleRe =
363
+ new RegExp(
364
+ String(frontMatterTitlePattern || "^\\s*\"?title\"?\\s*[:=]"),
365
+ "i"
366
+ );
367
+ return !ignoreFrontMatter &&
368
+ frontMatterLines.some((line) => frontMatterTitleRe.test(line));
369
+ };
370
+
371
+ /**
372
+ * Result object for getReferenceLinkImageData.
373
+ *
374
+ * @typedef {Object} GetReferenceLinkImageDataResult
375
+ * @property {Map<string, number[][]>} references References.
376
+ * @property {Map<string, number[][]>} shortcuts Shortcuts.
377
+ * @property {Map<string, [number, string]>} definitions Definitions.
378
+ * @property {[string, number][]} duplicateDefinitions Duplicate definitions.
379
+ * @property {number[]} definitionLineIndices Definition line indices.
380
+ */
381
+
382
+ /**
383
+ * Returns an object with information about reference links and images.
384
+ *
385
+ * @param {MicromarkToken[]} tokens Micromark tokens.
386
+ * @returns {GetReferenceLinkImageDataResult} Reference link/image data.
387
+ */
388
+ function getReferenceLinkImageData(tokens) {
389
+ const normalizeReference = (/** @type {string} */ s) => s.toLowerCase().trim().replace(/\s+/g, " ");
390
+ const getText = (/** @type {MicromarkToken} */ t) => t?.children.filter((c) => c.type !== "blockQuotePrefix").map((c) => c.text).join("");
391
+ /** @type {Map<string, number[][]>} */
392
+ const references = new Map();
393
+ /** @type {Map<string, number[][]>} */
394
+ const shortcuts = new Map();
395
+ const addReferenceToDictionary = (/** @type {MicromarkToken} */ token, /** @type {string} */ label, /** @type {boolean} */ isShortcut) => {
396
+ const referenceDatum = [
397
+ token.startLine - 1,
398
+ token.startColumn - 1,
399
+ token.text.length
400
+ ];
401
+ const reference = normalizeReference(label);
402
+ const dictionary = isShortcut ? shortcuts : references;
403
+ const referenceData = dictionary.get(reference) || [];
404
+ referenceData.push(referenceDatum);
405
+ dictionary.set(reference, referenceData);
406
+ };
407
+ /** @type {Map<string, [number, string]>} */
408
+ const definitions = new Map();
409
+ /** @type {number[]} */
410
+ const definitionLineIndices = [];
411
+ /** @type {[string, number][]} */
412
+ const duplicateDefinitions = [];
413
+ const filteredTokens =
414
+ micromark.filterByTypes(
415
+ tokens,
416
+ [
417
+ // definitionLineIndices
418
+ "definition", "gfmFootnoteDefinition",
419
+ // definitions and definitionLineIndices
420
+ "definitionLabelString", "gfmFootnoteDefinitionLabelString",
421
+ // references and shortcuts
422
+ "gfmFootnoteCall", "image", "link",
423
+ // undefined link labels
424
+ "undefinedReferenceCollapsed", "undefinedReferenceFull", "undefinedReferenceShortcut"
425
+ ]
426
+ );
427
+ for (const token of filteredTokens) {
428
+ let labelPrefix = "";
429
+ // eslint-disable-next-line default-case
430
+ switch (token.type) {
431
+ case "definition":
432
+ case "gfmFootnoteDefinition":
433
+ // definitionLineIndices
434
+ for (let i = token.startLine; i <= token.endLine; i++) {
435
+ definitionLineIndices.push(i - 1);
436
+ }
437
+ break;
438
+ case "gfmFootnoteDefinitionLabelString":
439
+ labelPrefix = "^";
440
+ case "definitionLabelString": // eslint-disable-line no-fallthrough
441
+ {
442
+ // definitions and definitionLineIndices
443
+ const reference = normalizeReference(`${labelPrefix}${token.text}`);
444
+ if (definitions.has(reference)) {
445
+ duplicateDefinitions.push([ reference, token.startLine - 1 ]);
446
+ } else {
447
+ const parent =
448
+ micromark.getParentOfType(token, [ "definition" ]);
449
+ const destinationString = parent &&
450
+ micromark.getDescendantsByType(parent, [ "definitionDestination", "definitionDestinationRaw", "definitionDestinationString" ])[0]?.text;
451
+ definitions.set(
452
+ reference,
453
+ [ token.startLine - 1, destinationString || "" ]
454
+ );
455
+ }
456
+ break;
457
+ }
458
+ case "gfmFootnoteCall":
459
+ case "image":
460
+ case "link":
461
+ {
462
+ // Identify if shortcut or full/collapsed
463
+ let isShortcut = (token.children.length === 1);
464
+ const isFullOrCollapsed = (token.children.length === 2) && !token.children.some((t) => t.type === "resource");
465
+ const [ labelText ] = micromark.getDescendantsByType(token, [ "label", "labelText" ]);
466
+ const [ referenceString ] = micromark.getDescendantsByType(token, [ "reference", "referenceString" ]);
467
+ let label = getText(labelText);
468
+ // Identify if footnote
469
+ if (!isShortcut && !isFullOrCollapsed) {
470
+ const [ footnoteCallMarker, footnoteCallString ] = token.children.filter(
471
+ (t) => [ "gfmFootnoteCallMarker", "gfmFootnoteCallString" ].includes(t.type)
472
+ );
473
+ if (footnoteCallMarker && footnoteCallString) {
474
+ label = `${footnoteCallMarker.text}${footnoteCallString.text}`;
475
+ isShortcut = true;
476
+ }
477
+ }
478
+ // Track link (handle shortcuts separately due to ambiguity in "text [text] text")
479
+ if (isShortcut || isFullOrCollapsed) {
480
+ addReferenceToDictionary(token, getText(referenceString) || label, isShortcut);
481
+ }
482
+ break;
483
+ }
484
+ case "undefinedReferenceCollapsed":
485
+ case "undefinedReferenceFull":
486
+ case "undefinedReferenceShortcut":
487
+ {
488
+ const undefinedReference = micromark.getDescendantsByType(token, [ "undefinedReference" ])[0];
489
+ const label = undefinedReference.children.map((t) => t.text).join("");
490
+ const isShortcut = (token.type === "undefinedReferenceShortcut");
491
+ addReferenceToDictionary(token, label, isShortcut);
492
+ break;
493
+ }
494
+ }
495
+ }
496
+ return {
497
+ references,
498
+ shortcuts,
499
+ definitions,
500
+ duplicateDefinitions,
501
+ definitionLineIndices
502
+ };
503
+ }
504
+ module.exports.getReferenceLinkImageData = getReferenceLinkImageData;
505
+
506
+ /**
507
+ * Gets the most common line ending, falling back to the platform default.
508
+ *
509
+ * @param {string} input Markdown content to analyze.
510
+ * @param {{EOL: string}} [os] Node.js "os" module.
511
+ * @returns {string} Preferred line ending.
512
+ */
513
+ function getPreferredLineEnding(input, os) {
514
+ let cr = 0;
515
+ let lf = 0;
516
+ let crlf = 0;
517
+ const endings = input.match(newlineRe) || [];
518
+ for (const ending of endings) {
519
+ // eslint-disable-next-line default-case
520
+ switch (ending) {
521
+ case "\r":
522
+ cr++;
523
+ break;
524
+ case "\n":
525
+ lf++;
526
+ break;
527
+ case "\r\n":
528
+ crlf++;
529
+ break;
530
+ }
531
+ }
532
+ let preferredLineEnding = null;
533
+ if (!cr && !lf && !crlf) {
534
+ preferredLineEnding = (os && os.EOL) || "\n";
535
+ } else if ((lf >= crlf) && (lf >= cr)) {
536
+ preferredLineEnding = "\n";
537
+ } else if (crlf >= cr) {
538
+ preferredLineEnding = "\r\n";
539
+ } else {
540
+ preferredLineEnding = "\r";
541
+ }
542
+ return preferredLineEnding;
543
+ }
544
+ module.exports.getPreferredLineEnding = getPreferredLineEnding;
545
+
546
+ /**
547
+ * Expands a path with a tilde to an absolute path.
548
+ *
549
+ * @param {string} file Path that may begin with a tilde.
550
+ * @param {{homedir: () => string}} os Node.js "os" module.
551
+ * @returns {string} Absolute path (or original path).
552
+ */
553
+ function expandTildePath(file, os) {
554
+ const homedir = os && os.homedir && os.homedir();
555
+ return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
556
+ }
557
+ module.exports.expandTildePath = expandTildePath;
558
+
559
+ /** @typedef {import("../lib/markdownlint.mjs").LintError[]} LintErrors */
560
+ /** @typedef {import("../lib/markdownlint.mjs").LintResults} LintResults */
561
+
562
+ /**
563
+ * Converts lint errors from resultVersion 3 to 2.
564
+ *
565
+ * @param {LintErrors} errors Lint errors (v3).
566
+ * @returns {LintErrors} Lint errors (v2).
567
+ */
568
+ function convertLintErrorsVersion3To2(errors) {
569
+ const noPrevious = {
570
+ "ruleNames": [],
571
+ "lineNumber": -1
572
+ };
573
+ return errors.filter((error, index, array) => {
574
+ // @ts-ignore
575
+ delete error.fixInfo;
576
+ // @ts-ignore
577
+ delete error.severity;
578
+ const previous = array[index - 1] || noPrevious;
579
+ return (
580
+ (error.ruleNames[0] !== previous.ruleNames[0]) ||
581
+ (error.lineNumber !== previous.lineNumber)
582
+ );
583
+ });
584
+ }
585
+
586
+ /**
587
+ * Converts lint errors from resultVersion 2 to 1.
588
+ *
589
+ * @param {LintErrors} errors Lint errors (v2).
590
+ * @returns {LintErrors} Lint errors (v1).
591
+ */
592
+ function convertLintErrorsVersion2To1(errors) {
593
+ for (const error of errors) {
594
+ // @ts-ignore
595
+ error.ruleName = error.ruleNames[0];
596
+ // @ts-ignore
597
+ error.ruleAlias = error.ruleNames[1] || error.ruleName;
598
+ // @ts-ignore
599
+ delete error.ruleNames;
600
+ }
601
+ return errors;
602
+ }
603
+
604
+ /**
605
+ * Converts lint errors from resultVersion 2 to 0.
606
+ *
607
+ * @param {LintErrors} errors Lint errors (v2).
608
+ * @returns {LintErrors} Lint errors (v0).
609
+ */
610
+ function convertLintErrorsVersion2To0(errors) {
611
+ /** @type {Object.<string, number[]>} */
612
+ const dictionary = {};
613
+ for (const error of errors) {
614
+ const ruleName = error.ruleNames[0];
615
+ const ruleLines = dictionary[ruleName] || [];
616
+ ruleLines.push(error.lineNumber);
617
+ dictionary[ruleName] = ruleLines;
618
+ }
619
+ // @ts-ignore
620
+ return dictionary;
621
+ }
622
+
623
+ /**
624
+ * Copies and transforms lint results from resultVersion 3 to ?.
625
+ *
626
+ * @param {LintResults} results Lint results (v3).
627
+ * @param {(errors: LintErrors) => LintErrors} transform Lint errors (v?).
628
+ * @returns {LintResults} Lint results (v?).
629
+ */
630
+ function copyAndTransformResults(results, transform) {
631
+ /** @type {Object.<string, LintErrors>} */
632
+ const newResults = {};
633
+ for (const key of Object.keys(results)) {
634
+ const arr = results[key].map((r) => ({ ...r }));
635
+ newResults[key] = transform(arr);
636
+ }
637
+ // @ts-ignore
638
+ return newResults;
639
+ }
640
+
641
+ /**
642
+ * Converts lint results from resultVersion 3 to 0.
643
+ *
644
+ * @param {LintResults} results Lint results (v3).
645
+ * @returns {LintResults} Lint results (v0).
646
+ */
647
+ module.exports.convertToResultVersion0 = function convertToResultVersion0(results) {
648
+ return copyAndTransformResults(results, (r) => convertLintErrorsVersion2To0(convertLintErrorsVersion3To2(r)));
649
+ };
650
+
651
+ /**
652
+ * Converts lint results from resultVersion 3 to 1.
653
+ *
654
+ * @param {LintResults} results Lint results (v3).
655
+ * @returns {LintResults} Lint results (v1).
656
+ */
657
+ module.exports.convertToResultVersion1 = function convertToResultVersion1(results) {
658
+ return copyAndTransformResults(results, (r) => convertLintErrorsVersion2To1(convertLintErrorsVersion3To2(r)));
659
+ };
660
+
661
+ /**
662
+ * Converts lint results from resultVersion 3 to 2.
663
+ *
664
+ * @param {LintResults} results Lint results (v3).
665
+ * @returns {LintResults} Lint results (v2).
666
+ */
667
+ module.exports.convertToResultVersion2 = function convertToResultVersion2(results) {
668
+ return copyAndTransformResults(results, convertLintErrorsVersion3To2);
669
+ };
670
+
671
+ /**
672
+ * Formats lint results to an array of strings.
673
+ *
674
+ * @param {LintResults|undefined} lintResults Lint results.
675
+ * @returns {string[]} Lint error strings.
676
+ */
677
+ module.exports.formatLintResults = function formatLintResults(lintResults) {
678
+ const results = [];
679
+ const entries = Object.entries(lintResults || {});
680
+ entries.sort((a, b) => a[0].localeCompare(b[0]));
681
+ for (const [ source, lintErrors ] of entries) {
682
+ for (const lintError of lintErrors) {
683
+ const { lineNumber, ruleNames, ruleDescription, errorDetail, errorContext, errorRange, severity } = lintError;
684
+ const rule = ruleNames.join("/");
685
+ const line = `:${lineNumber}`;
686
+ const rangeStart = (errorRange && errorRange[0]) || 0;
687
+ const column = rangeStart ? `:${rangeStart}` : "";
688
+ const description = ruleDescription;
689
+ const detail = (errorDetail ? ` [${errorDetail}]` : "");
690
+ const context = (errorContext ? ` [Context: "${errorContext}"]` : "");
691
+ results.push(`${source}${line}${column} ${severity} ${rule} ${description}${detail}${context}`);
692
+ }
693
+ }
694
+ return results;
695
+ };