@alexlit/lint-kit 189.0.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 (179) hide show
  1. package/package.json +1 -1
  2. package/packages/config-eslint/package.json +6 -6
  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-prettier/package.json +2 -2
  176. package/packages/config-stylelint/index.js +1 -1
  177. package/packages/config-stylelint/package.json +3 -3
  178. package/packages/config-stylelint/plugins/scss.js +1 -1
  179. package/packages/config-stylelint/plugins/selector-no-empty.js +1 -1
@@ -0,0 +1,332 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { flatTokensSymbol, htmlFlowSymbol, newlineRe } = require("./shared.cjs");
6
+
7
+ // eslint-disable-next-line jsdoc/valid-types
8
+ /** @typedef {import("micromark-util-types", { with: { "resolution-mode": "import" } }).TokenType} TokenType */
9
+ /** @typedef {import("../lib/exports.mjs").MicromarkToken} Token */
10
+ // eslint-disable-next-line jsdoc/valid-types
11
+ /** @typedef {import("../lib/micromark-types.d.mts", { with: { "resolution-mode": "import" } })} */
12
+
13
+ /**
14
+ * Determines if a Micromark token is within an htmlFlow type.
15
+ *
16
+ * @param {Token} token Micromark token.
17
+ * @returns {boolean} True iff the token is within an htmlFlow type.
18
+ */
19
+ function inHtmlFlow(token) {
20
+ // @ts-ignore
21
+ return Boolean(token[htmlFlowSymbol]);
22
+ }
23
+
24
+ /**
25
+ * Returns whether a token is an htmlFlow type containing an HTML comment.
26
+ *
27
+ * @param {Token} token Micromark token.
28
+ * @returns {boolean} True iff token is htmlFlow containing a comment.
29
+ */
30
+ function isHtmlFlowComment(token) {
31
+ const { text, type } = token;
32
+ if (
33
+ (type === "htmlFlow") &&
34
+ text.startsWith("<!--") &&
35
+ text.endsWith("-->")
36
+ ) {
37
+ const comment = text.slice(4, -3);
38
+ return (
39
+ !comment.startsWith(">") &&
40
+ !comment.startsWith("->") &&
41
+ !comment.endsWith("-")
42
+ // The following condition from the CommonMark specification is commented
43
+ // to avoid parsing HTML comments that include "--" because that is NOT a
44
+ // condition of the HTML specification.
45
+ // https://spec.commonmark.org/0.30/#raw-html
46
+ // https://html.spec.whatwg.org/multipage/syntax.html#comments
47
+ // && !comment.includes("--")
48
+ );
49
+ }
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Adds a range of numbers to a set.
55
+ *
56
+ * @param {Set<number>} set Set of numbers.
57
+ * @param {number} start Starting number.
58
+ * @param {number} end Ending number.
59
+ * @returns {void}
60
+ */
61
+ function addRangeToSet(set, start, end) {
62
+ for (let i = start; i <= end; i++) {
63
+ set.add(i);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @callback AllowedPredicate
69
+ * @param {Token} token Micromark token.
70
+ * @returns {boolean} True iff allowed.
71
+ */
72
+
73
+ /**
74
+ * @callback TransformPredicate
75
+ * @param {Token} token Micromark token.
76
+ * @returns {Token[]} Child tokens.
77
+ */
78
+
79
+ /**
80
+ * Filter a list of Micromark tokens by predicate.
81
+ *
82
+ * @param {Token[]} tokens Micromark tokens.
83
+ * @param {AllowedPredicate} allowed Allowed token predicate.
84
+ * @param {TransformPredicate} [transformChildren] Transform predicate.
85
+ * @returns {Token[]} Filtered tokens.
86
+ */
87
+ function filterByPredicate(tokens, allowed, transformChildren) {
88
+ const result = [];
89
+ const queue = [
90
+ {
91
+ "array": tokens,
92
+ "index": 0
93
+ }
94
+ ];
95
+ while (queue.length > 0) {
96
+ const current = queue[queue.length - 1];
97
+ const { array, index } = current;
98
+ if (index < array.length) {
99
+ const token = array[current.index++];
100
+ if (allowed(token)) {
101
+ result.push(token);
102
+ }
103
+ const { children } = token;
104
+ if (children.length > 0) {
105
+ const transformed =
106
+ transformChildren ? transformChildren(token) : children;
107
+ queue.push(
108
+ {
109
+ "array": transformed,
110
+ "index": 0
111
+ }
112
+ );
113
+ }
114
+ } else {
115
+ queue.pop();
116
+ }
117
+ }
118
+ return result;
119
+ }
120
+
121
+ /**
122
+ * Filter a list of Micromark tokens by type.
123
+ *
124
+ * @param {Token[]} tokens Micromark tokens.
125
+ * @param {TokenType[]} types Types to allow.
126
+ * @param {boolean} [htmlFlow] Whether to include htmlFlow content.
127
+ * @returns {Token[]} Filtered tokens.
128
+ */
129
+ function filterByTypes(tokens, types, htmlFlow) {
130
+ const predicate = (/** @type {Token} */ token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
131
+ /** @type {Token[]} */
132
+ const flatTokens =
133
+ // @ts-ignore
134
+ tokens[flatTokensSymbol];
135
+ if (flatTokens) {
136
+ return flatTokens.filter(predicate);
137
+ }
138
+ return filterByPredicate(tokens, predicate);
139
+ }
140
+
141
+ /**
142
+ * Gets the blockquote prefix text (if any) for the specified line number.
143
+ *
144
+ * @param {Token[]} tokens Micromark tokens.
145
+ * @param {number} lineNumber Line number to examine.
146
+ * @param {number} [count] Number of times to repeat.
147
+ * @returns {string} Blockquote prefix text.
148
+ */
149
+ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
150
+ return filterByTypes(tokens, [ "blockQuotePrefix", "linePrefix" ])
151
+ .filter((prefix) => prefix.startLine === lineNumber)
152
+ .map((prefix) => prefix.text)
153
+ .join("")
154
+ .trimEnd()
155
+ .concat("\n")
156
+ .repeat(count);
157
+ };
158
+
159
+ /**
160
+ * Gets a list of nested Micromark token descendants by type path.
161
+ *
162
+ * @param {Token|Token[]} parent Micromark token parent or parents.
163
+ * @param {(TokenType|TokenType[])[]} typePath Micromark token type path.
164
+ * @returns {Token[]} Micromark token descendants.
165
+ */
166
+ function getDescendantsByType(parent, typePath) {
167
+ let tokens = Array.isArray(parent) ? parent : [ parent ];
168
+ for (const type of typePath) {
169
+ const predicate = (/** @type {Token} */ token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
170
+ tokens = tokens.flatMap((t) => t.children.filter(predicate));
171
+ }
172
+ return tokens;
173
+ }
174
+
175
+ /**
176
+ * Gets the heading level of a Micromark heading tokan.
177
+ *
178
+ * @param {Token} heading Micromark heading token.
179
+ * @returns {number} Heading level.
180
+ */
181
+ function getHeadingLevel(heading) {
182
+ let level = 1;
183
+ const headingSequence = heading.children.find(
184
+ (child) => [ "atxHeadingSequence", "setextHeadingLine" ].includes(child.type)
185
+ );
186
+ // @ts-ignore
187
+ const { text } = headingSequence;
188
+ if (text[0] === "#") {
189
+ level = Math.min(text.length, 6);
190
+ } else if (text[0] === "-") {
191
+ level = 2;
192
+ }
193
+ return level;
194
+ }
195
+
196
+ /**
197
+ * Gets the heading style of a Micromark heading tokan.
198
+ *
199
+ * @param {Token} heading Micromark heading token.
200
+ * @returns {"atx" | "atx_closed" | "setext"} Heading style.
201
+ */
202
+ function getHeadingStyle(heading) {
203
+ if (heading.type === "setextHeading") {
204
+ return "setext";
205
+ }
206
+ const atxHeadingSequenceLength = heading.children.filter(
207
+ (child) => child.type === "atxHeadingSequence"
208
+ ).length;
209
+ if (atxHeadingSequenceLength === 1) {
210
+ return "atx";
211
+ }
212
+ return "atx_closed";
213
+ }
214
+
215
+ /**
216
+ * Gets the heading text of a Micromark heading token.
217
+ *
218
+ * @param {Token} heading Micromark heading token.
219
+ * @returns {string} Heading text.
220
+ */
221
+ function getHeadingText(heading) {
222
+ return getDescendantsByType(heading, [ [ "atxHeadingText", "setextHeadingText" ] ])
223
+ .flatMap((descendant) => descendant.children.filter((child) => child.type !== "htmlText"))
224
+ .map((data) => data.text)
225
+ .join("")
226
+ .replace(newlineRe, " ");
227
+ }
228
+
229
+ /**
230
+ * HTML tag information.
231
+ *
232
+ * @typedef {Object} HtmlTagInfo
233
+ * @property {boolean} close True iff close tag.
234
+ * @property {string} name Tag name.
235
+ */
236
+
237
+ /**
238
+ * Gets information about the tag in an HTML token.
239
+ *
240
+ * @param {Token} token Micromark token.
241
+ * @returns {HtmlTagInfo | null} HTML tag information.
242
+ */
243
+ function getHtmlTagInfo(token) {
244
+ const htmlTagNameRe = /^<([^!>][^/\s>]*)/;
245
+ if (token.type === "htmlText") {
246
+ const match = htmlTagNameRe.exec(token.text);
247
+ if (match) {
248
+ const name = match[1];
249
+ const close = name.startsWith("/");
250
+ return {
251
+ close,
252
+ "name": close ? name.slice(1) : name
253
+ };
254
+ }
255
+ }
256
+ return null;
257
+ }
258
+
259
+ /**
260
+ * Gets the nearest parent of the specified type for a Micromark token.
261
+ *
262
+ * @param {Token} token Micromark token.
263
+ * @param {TokenType[]} types Types to allow.
264
+ * @returns {Token | null} Parent token.
265
+ */
266
+ function getParentOfType(token, types) {
267
+ /** @type {Token | null} */
268
+ let current = token;
269
+ while ((current = current.parent) && !types.includes(current.type)) {
270
+ // Empty
271
+ }
272
+ return current;
273
+ }
274
+
275
+ const docfxTabSyntaxRe = /^#tab\//;
276
+
277
+ /**
278
+ * Returns whether the specified Micromark token looks like a Docfx tab.
279
+ *
280
+ * @param {Token | null} heading Micromark token.
281
+ * @returns {boolean} True iff the token looks like a Docfx tab.
282
+ */
283
+ function isDocfxTab(heading) {
284
+ // See https://dotnet.github.io/docfx/docs/markdown.html?tabs=linux%2Cdotnet#tabs
285
+ if (heading?.type === "atxHeading") {
286
+ const headingTexts = getDescendantsByType(heading, [ "atxHeadingText" ]);
287
+ // eslint-disable-next-line unicorn/better-dom-traversing
288
+ if ((headingTexts.length === 1) && (headingTexts[0].children.length === 1) && (headingTexts[0].children[0].type === "link")) {
289
+ // eslint-disable-next-line unicorn/better-dom-traversing
290
+ const resourceDestinationStrings = filterByTypes(headingTexts[0].children[0].children, [ "resourceDestinationString" ]);
291
+ return (resourceDestinationStrings.length === 1) && docfxTabSyntaxRe.test(resourceDestinationStrings[0].text);
292
+ }
293
+ }
294
+ return false;
295
+ }
296
+
297
+ /**
298
+ * Set containing token types that do not contain content.
299
+ *
300
+ * @type {Set<TokenType>}
301
+ */
302
+ const nonContentTokens = new Set([
303
+ "blockQuoteMarker",
304
+ "blockQuotePrefix",
305
+ "blockQuotePrefixWhitespace",
306
+ "gfmFootnoteDefinitionIndent",
307
+ "lineEnding",
308
+ "lineEndingBlank",
309
+ "linePrefix",
310
+ "listItemIndent",
311
+ "undefinedReference",
312
+ "undefinedReferenceCollapsed",
313
+ "undefinedReferenceFull",
314
+ "undefinedReferenceShortcut"
315
+ ]);
316
+
317
+ module.exports = {
318
+ addRangeToSet,
319
+ filterByPredicate,
320
+ filterByTypes,
321
+ getBlockQuotePrefixText,
322
+ getDescendantsByType,
323
+ getHeadingLevel,
324
+ getHeadingStyle,
325
+ getHeadingText,
326
+ getHtmlTagInfo,
327
+ getParentOfType,
328
+ inHtmlFlow,
329
+ isDocfxTab,
330
+ isHtmlFlowComment,
331
+ nonContentTokens
332
+ };
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "markdownlint-rule-helpers",
3
+ "version": "0.31.0",
4
+ "description": "A collection of markdownlint helper functions for custom rules",
5
+ "main": "./helpers.cjs",
6
+ "exports": {
7
+ ".": "./helpers.cjs",
8
+ "./micromark": "./micromark-helpers.cjs"
9
+ },
10
+ "author": "David Anson (https://dlaa.me/)",
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/DavidAnson/markdownlint",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/DavidAnson/markdownlint.git"
16
+ },
17
+ "bugs": "https://github.com/DavidAnson/markdownlint/issues",
18
+ "funding": "https://github.com/sponsors/DavidAnson",
19
+ "engines": {
20
+ "node": ">=22"
21
+ },
22
+ "keywords": [
23
+ "markdownlint",
24
+ "markdownlint-rule"
25
+ ]
26
+ }
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ // Symbol for identifing the flat tokens array from micromark parse
6
+ module.exports.flatTokensSymbol = Symbol("flat-tokens");
7
+
8
+ // Symbol for identifying the htmlFlow token from micromark parse
9
+ module.exports.htmlFlowSymbol = Symbol("html-flow");
10
+
11
+ // Regular expression for matching common newline characters
12
+ // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
13
+ module.exports.newlineRe = /\r\n?|\n/g;
14
+
15
+ // Regular expression for matching next lines
16
+ module.exports.nextLinesRe = /[\r\n][\s\S]*$/;
@@ -0,0 +1,80 @@
1
+ // @ts-check
2
+
3
+ import { getReferenceLinkImageData as helpersGetReferenceLinkImageData } from "../helpers/helpers.cjs";
4
+ import { filterByTypes } from "../helpers/micromark-helpers.cjs";
5
+
6
+ /** @typedef {import("markdownlint").RuleParams} RuleParams */
7
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
8
+ /** @typedef {import("markdownlint").MicromarkTokenType} MicromarkTokenType */
9
+ /** @typedef {import("../helpers/helpers.cjs").GetReferenceLinkImageDataResult} GetReferenceLinkImageDataResult */
10
+
11
+ /** @type {Map<string, object>} */
12
+ const map = new Map();
13
+ /** @type {RuleParams | undefined} */
14
+ let params = undefined;
15
+
16
+ /**
17
+ * Initializes (resets) the cache.
18
+ *
19
+ * @param {RuleParams} [p] Rule parameters object.
20
+ * @returns {void}
21
+ */
22
+ export function initialize(p) {
23
+ map.clear();
24
+ params = p;
25
+ }
26
+
27
+ /**
28
+ * Gets the cached Micromark token array (for testing).
29
+ *
30
+ * @returns {MicromarkToken[]} Micromark tokens.
31
+ */
32
+ export function micromarkTokens() {
33
+ return params?.parsers.micromark.tokens || [];
34
+ }
35
+
36
+ /**
37
+ * Gets a cached object value - computes it and caches it.
38
+ *
39
+ * @param {string} name Cache object name.
40
+ * @param {() => Object} getValue Getter for object value.
41
+ * @returns {Object} Object value.
42
+ */
43
+ function getCached(name, getValue) {
44
+ if (map.has(name)) {
45
+ // @ts-ignore
46
+ return map.get(name);
47
+ }
48
+ const value = getValue();
49
+ map.set(name, value);
50
+ return value;
51
+ }
52
+
53
+ /**
54
+ * Filters a list of Micromark tokens by type and caches the result.
55
+ *
56
+ * @param {MicromarkTokenType[]} types Types to allow.
57
+ * @param {boolean} [htmlFlow] Whether to include htmlFlow content.
58
+ * @returns {MicromarkToken[]} Filtered tokens.
59
+ */
60
+ export function filterByTypesCached(types, htmlFlow) {
61
+ // @ts-ignore
62
+ return getCached(
63
+ // eslint-disable-next-line prefer-rest-params
64
+ JSON.stringify(arguments),
65
+ () => filterByTypes(micromarkTokens(), types, htmlFlow)
66
+ );
67
+ }
68
+
69
+ /**
70
+ * Gets a reference link and image data object.
71
+ *
72
+ * @returns {GetReferenceLinkImageDataResult} Reference link and image data object.
73
+ */
74
+ export function getReferenceLinkImageData() {
75
+ // @ts-ignore
76
+ return getCached(
77
+ getReferenceLinkImageData.name,
78
+ () => helpersGetReferenceLinkImageData(micromarkTokens())
79
+ );
80
+ }