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