@alexlit/lint-kit 127.2.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 (141) hide show
  1. package/package.json +1 -1
  2. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +457 -0
  3. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +93 -0
  4. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
  5. package/packages/config-markdownlint/node_modules/markdownlint/README.md +1047 -0
  6. package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +7094 -0
  7. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +388 -0
  8. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
  9. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
  10. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2528 -0
  11. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
  12. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
  13. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
  14. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
  15. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
  16. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
  17. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
  18. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
  19. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
  20. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +58 -0
  21. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
  22. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
  23. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
  24. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
  25. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
  26. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
  27. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
  28. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +44 -0
  29. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
  30. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
  31. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
  32. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
  33. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
  34. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
  35. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
  36. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
  37. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
  38. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +55 -0
  39. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
  40. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
  41. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
  42. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
  43. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
  44. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
  45. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
  46. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
  47. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
  48. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +45 -0
  49. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
  50. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
  51. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
  52. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
  53. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +35 -0
  54. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +35 -0
  55. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +87 -0
  56. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
  57. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
  58. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
  59. package/packages/config-markdownlint/node_modules/markdownlint/doc/md055.md +54 -0
  60. package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +37 -0
  61. package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +48 -0
  62. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
  63. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +46 -0
  64. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +793 -0
  65. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +544 -0
  66. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
  67. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
  68. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +70 -0
  69. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +1185 -0
  70. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +8 -0
  71. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +15 -0
  72. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +488 -0
  73. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1572 -0
  74. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +31 -0
  75. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +50 -0
  76. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +86 -0
  77. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +72 -0
  78. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +88 -0
  79. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +95 -0
  80. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +78 -0
  81. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +57 -0
  82. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +43 -0
  83. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +105 -0
  84. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +54 -0
  85. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +46 -0
  86. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.js +80 -0
  87. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +71 -0
  88. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +106 -0
  89. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +40 -0
  90. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +48 -0
  91. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +40 -0
  92. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +49 -0
  93. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +37 -0
  94. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +42 -0
  95. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +76 -0
  96. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +60 -0
  97. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +63 -0
  98. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +66 -0
  99. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +41 -0
  100. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +100 -0
  101. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +26 -0
  102. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +51 -0
  103. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +94 -0
  104. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +100 -0
  105. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +83 -0
  106. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
  107. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +37 -0
  108. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +63 -0
  109. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +73 -0
  110. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +110 -0
  111. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +62 -0
  112. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +34 -0
  113. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +31 -0
  114. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +39 -0
  115. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +103 -0
  116. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +170 -0
  117. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +42 -0
  118. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +62 -0
  119. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
  120. package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.js +79 -0
  121. package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.js +56 -0
  122. package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.js +43 -0
  123. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +74 -0
  124. package/packages/config-markdownlint/node_modules/markdownlint/package.json +105 -0
  125. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +307 -0
  126. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +275 -0
  127. package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +26 -0
  128. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +1819 -0
  129. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1824 -0
  130. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
  131. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
  132. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +27 -0
  133. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
  134. package/packages/config-markdownlint/node_modules/markdownlint-micromark/LICENSE +21 -0
  135. package/packages/config-markdownlint/node_modules/markdownlint-micromark/README.md +10 -0
  136. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-browser.js +2 -0
  137. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-html-browser.js +2 -0
  138. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.cjs +1 -0
  139. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.d.cts +1751 -0
  140. package/packages/config-markdownlint/node_modules/markdownlint-micromark/package.json +46 -0
  141. package/packages/config-markdownlint/package.json +2 -2
@@ -0,0 +1,100 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { tokenIfType } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ const leftSpaceRe = /^\s(?:[^`]|$)/;
10
+ const rightSpaceRe = /[^`]\s$/;
11
+ const trimCodeText = (text, start, end) => {
12
+ text = text.replace(/^\s+$/, "");
13
+ if (start) {
14
+ text = text.replace(/^\s+?(\s`|\S)/, "$1");
15
+ }
16
+ if (end) {
17
+ text = text.replace(/(`\s|\S)\s+$/, "$1");
18
+ }
19
+ return text;
20
+ };
21
+
22
+ // eslint-disable-next-line jsdoc/valid-types
23
+ /** @type import("./markdownlint").Rule */
24
+ module.exports = {
25
+ "names": [ "MD038", "no-space-in-code" ],
26
+ "description": "Spaces inside code span elements",
27
+ "tags": [ "whitespace", "code" ],
28
+ "parser": "micromark",
29
+ "function": function MD038(params, onError) {
30
+ const codeTexts = filterByTypesCached([ "codeText" ]);
31
+ for (const codeText of codeTexts) {
32
+ const { children } = codeText;
33
+ const first = 0;
34
+ const last = children.length - 1;
35
+ const startSequence = tokenIfType(children[first], "codeTextSequence");
36
+ const endSequence = tokenIfType(children[last], "codeTextSequence");
37
+ const startData =
38
+ tokenIfType(children[first + 1], "codeTextData") ||
39
+ tokenIfType(children[first + 2], "codeTextData");
40
+ const endData =
41
+ tokenIfType(children[last - 1], "codeTextData") ||
42
+ tokenIfType(children[last - 2], "codeTextData");
43
+ if (startSequence && endSequence && startData && endData) {
44
+ const spaceLeft = leftSpaceRe.test(startData.text);
45
+ const spaceRight = rightSpaceRe.test(endData.text);
46
+ if (spaceLeft || spaceRight) {
47
+ let lineNumber = startSequence.startLine;
48
+ let range = null;
49
+ let fixInfo = null;
50
+ if (startSequence.startLine === endSequence.endLine) {
51
+ range = [
52
+ startSequence.startColumn,
53
+ endSequence.endColumn - startSequence.startColumn
54
+ ];
55
+ fixInfo = {
56
+ "editColumn": startSequence.endColumn,
57
+ "deleteCount": endSequence.startColumn - startSequence.endColumn,
58
+ "insertText": trimCodeText(startData.text, true, true)
59
+ };
60
+ } else if (spaceLeft && (startSequence.endLine === startData.startLine)) {
61
+ range = [
62
+ startSequence.startColumn,
63
+ startData.endColumn - startSequence.startColumn
64
+ ];
65
+ fixInfo = {
66
+ "editColumn": startSequence.endColumn,
67
+ "deleteCount": startData.endColumn - startData.startColumn,
68
+ "insertText": trimCodeText(startData.text, true, false)
69
+ };
70
+ } else if (spaceRight && (endData.text.trim().length > 0)) {
71
+ lineNumber = endSequence.endLine;
72
+ range = [
73
+ endData.startColumn,
74
+ endSequence.endColumn - endData.startColumn
75
+ ];
76
+ fixInfo = {
77
+ "editColumn": endData.startColumn,
78
+ "deleteCount": endData.endColumn - endData.startColumn,
79
+ "insertText": trimCodeText(endData.text, false, true)
80
+ };
81
+ }
82
+ if (range) {
83
+ const context = params
84
+ .lines[lineNumber - 1]
85
+ .substring(range[0] - 1, range[0] - 1 + range[1]);
86
+ addErrorContext(
87
+ onError,
88
+ lineNumber,
89
+ context,
90
+ spaceLeft,
91
+ spaceRight,
92
+ range,
93
+ fixInfo
94
+ );
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ };
@@ -0,0 +1,83 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { filterByTypes } = require("../helpers/micromark.cjs");
7
+ const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
8
+
9
+ /**
10
+ * Adds an error for a label space issue.
11
+ *
12
+ * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
13
+ * @param {import("../helpers/micromark.cjs").Token} label Label token.
14
+ * @param {import("../helpers/micromark.cjs").Token} labelText LabelText token.
15
+ * @param {boolean} isStart True iff error is at the start of the link.
16
+ */
17
+ function addLabelSpaceError(onError, label, labelText, isStart) {
18
+ const match = labelText.text.match(isStart ? /^[^\S\r\n]+/ : /[^\S\r\n]+$/);
19
+ const range = match ?
20
+ [
21
+ (isStart ? (labelText.startColumn) : (labelText.endColumn - match[0].length)),
22
+ match[0].length
23
+ ] :
24
+ undefined;
25
+ addErrorContext(
26
+ onError,
27
+ isStart ? (labelText.startLine + (match ? 0 : 1)) : (labelText.endLine - (match ? 0 : 1)),
28
+ label.text.replace(/\s+/g, " "),
29
+ isStart,
30
+ !isStart,
31
+ range,
32
+ range ? {
33
+ "editColumn": range[0],
34
+ "deleteCount": range[1]
35
+ } : undefined
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Determines if a link is a valid link (and not a fake shortcut link due to parser tricks).
41
+ *
42
+ * @param {import("../helpers/micromark.cjs").Token} label Label token.
43
+ * @param {import("../helpers/micromark.cjs").Token} labelText LabelText token.
44
+ * @param {Map<string, any>} definitions Map of link definitions.
45
+ * @returns {boolean} True iff the link is valid.
46
+ */
47
+ function validLink(label, labelText, definitions) {
48
+ return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim());
49
+ }
50
+
51
+ // eslint-disable-next-line jsdoc/valid-types
52
+ /** @type import("./markdownlint").Rule */
53
+ module.exports = {
54
+ "names": [ "MD039", "no-space-in-links" ],
55
+ "description": "Spaces inside link text",
56
+ "tags": [ "whitespace", "links" ],
57
+ "parser": "micromark",
58
+ "function": function MD039(params, onError) {
59
+ const { definitions } = getReferenceLinkImageData();
60
+ const labels = filterByTypesCached([ "label" ]).
61
+ filter((label) => label.parent?.type === "link");
62
+ for (const label of labels) {
63
+ const labelTexts = filterByTypes(
64
+ label.children,
65
+ [ "labelText" ]
66
+ );
67
+ for (const labelText of labelTexts) {
68
+ if (
69
+ (labelText.text.trimStart().length !== labelText.text.length) &&
70
+ validLink(label, labelText, definitions)
71
+ ) {
72
+ addLabelSpaceError(onError, label, labelText, true);
73
+ }
74
+ if (
75
+ (labelText.text.trimEnd().length !== labelText.text.length) &&
76
+ validLink(label, labelText, definitions)
77
+ ) {
78
+ addLabelSpaceError(onError, label, labelText, false);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ };
@@ -0,0 +1,37 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addError, addErrorContext } = require("../helpers");
6
+ const { getTokenTextByType, tokenIfType } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD040", "fenced-code-language" ],
13
+ "description": "Fenced code blocks should have a language specified",
14
+ "tags": [ "code", "language" ],
15
+ "parser": "micromark",
16
+ "function": function MD040(params, onError) {
17
+ let allowed = params.config.allowed_languages;
18
+ allowed = Array.isArray(allowed) ? allowed : [];
19
+ const languageOnly = !!params.config.language_only;
20
+ const fencedCodes = filterByTypesCached([ "codeFenced" ]);
21
+ for (const fencedCode of fencedCodes) {
22
+ const openingFence = tokenIfType(fencedCode.children[0], "codeFencedFence");
23
+ if (openingFence) {
24
+ const { children, startLine, text } = openingFence;
25
+ const info = getTokenTextByType(children, "codeFencedFenceInfo");
26
+ if (!info) {
27
+ addErrorContext(onError, startLine, text);
28
+ } else if ((allowed.length > 0) && !allowed.includes(info)) {
29
+ addError(onError, startLine, `"${info}" is not allowed`);
30
+ }
31
+ if (languageOnly && getTokenTextByType(children, "codeFencedFenceMeta")) {
32
+ addError(onError, startLine, `Info string contains more than language: "${text}"`);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ };
@@ -0,0 +1,37 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext, frontMatterHasTitle } = require("../helpers");
6
+ const { filterByTypes, getHeadingLevel, getHtmlTagInfo, isHtmlFlowComment, nonContentTokens } =
7
+ require("../helpers/micromark.cjs");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD041", "first-line-heading", "first-line-h1" ],
13
+ "description": "First line in a file should be a top-level heading",
14
+ "tags": [ "headings" ],
15
+ "parser": "micromark",
16
+ "function": function MD041(params, onError) {
17
+ const level = Number(params.config.level || 1);
18
+ if (!frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title)) {
19
+ params.parsers.micromark.tokens.
20
+ filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token)).
21
+ every((token) => {
22
+ let isError = true;
23
+ if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
24
+ isError = (getHeadingLevel(token) !== level);
25
+ } else if (token.type === "htmlFlow") {
26
+ const htmlTexts = filterByTypes(token.children, [ "htmlText" ], true);
27
+ const tagInfo = (htmlTexts.length > 0) && getHtmlTagInfo(htmlTexts[0]);
28
+ isError = !tagInfo || (tagInfo.name.toLowerCase() !== `h${level}`);
29
+ }
30
+ if (isError) {
31
+ addErrorContext(onError, token.startLine, params.lines[token.startLine - 1]);
32
+ }
33
+ return false;
34
+ });
35
+ }
36
+ }
37
+ };
@@ -0,0 +1,63 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { getDescendantsByType } = require("../helpers/micromark.cjs");
7
+ const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD042", "no-empty-links" ],
13
+ "description": "No empty links",
14
+ "tags": [ "links" ],
15
+ "parser": "micromark",
16
+ "function": function MD042(params, onError) {
17
+ const { definitions } = getReferenceLinkImageData();
18
+ const isReferenceDefinitionHash = (token) => {
19
+ const definition = definitions.get(token.text.trim());
20
+ return (definition && (definition[1] === "#"));
21
+ };
22
+ const links = filterByTypesCached([ "link" ]);
23
+ for (const link of links) {
24
+ const labelText = getDescendantsByType(link, [ "label", "labelText" ]);
25
+ const reference = getDescendantsByType(link, [ "reference" ]);
26
+ const resource = getDescendantsByType(link, [ "resource" ]);
27
+ const referenceString = getDescendantsByType(reference, [ "referenceString" ]);
28
+ const resourceDestination = getDescendantsByType(resource, [ "resourceDestination" ]);
29
+ const resourceDestinationString = [
30
+ ...getDescendantsByType(resourceDestination, [ "resourceDestinationRaw", "resourceDestinationString" ]),
31
+ ...getDescendantsByType(resourceDestination, [ "resourceDestinationLiteral", "resourceDestinationString" ])
32
+ ];
33
+ const hasLabelText = labelText.length > 0;
34
+ const hasReference = reference.length > 0;
35
+ const hasResource = resource.length > 0;
36
+ const hasReferenceString = referenceString.length > 0;
37
+ const hasResourceDestinationString = resourceDestinationString.length > 0;
38
+ let error = false;
39
+ if (
40
+ hasLabelText &&
41
+ ((!hasReference && !hasResource) || (hasReference && !hasReferenceString))
42
+ ) {
43
+ error = isReferenceDefinitionHash(labelText[0]);
44
+ } else if (hasReferenceString && !hasResourceDestinationString) {
45
+ error = isReferenceDefinitionHash(referenceString[0]);
46
+ } else if (!hasReferenceString && hasResourceDestinationString) {
47
+ error = (resourceDestinationString[0].text.trim() === "#");
48
+ } else if (!hasReferenceString && !hasResourceDestinationString) {
49
+ error = true;
50
+ }
51
+ if (error) {
52
+ addErrorContext(
53
+ onError,
54
+ link.startLine,
55
+ link.text,
56
+ undefined,
57
+ undefined,
58
+ [ link.startColumn, link.endColumn - link.startColumn ]
59
+ );
60
+ }
61
+ }
62
+ }
63
+ };
@@ -0,0 +1,73 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext, addErrorDetailIf } = require("../helpers");
6
+ const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD043", "required-headings" ],
13
+ "description": "Required heading structure",
14
+ "tags": [ "headings" ],
15
+ "parser": "micromark",
16
+ "function": function MD043(params, onError) {
17
+ const requiredHeadings = params.config.headings;
18
+ if (!Array.isArray(requiredHeadings)) {
19
+ // Nothing to check; avoid doing any work
20
+ return;
21
+ }
22
+ const matchCase = params.config.match_case || false;
23
+ let i = 0;
24
+ let matchAny = false;
25
+ let hasError = false;
26
+ let anyHeadings = false;
27
+ const getExpected = () => requiredHeadings[i++] || "[None]";
28
+ const handleCase = (str) => (matchCase ? str : str.toLowerCase());
29
+ for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
30
+ if (!hasError) {
31
+ const headingText = getHeadingText(heading);
32
+ const headingLevel = getHeadingLevel(heading);
33
+ anyHeadings = true;
34
+ const actual = `${"".padEnd(headingLevel, "#")} ${headingText}`;
35
+ const expected = getExpected();
36
+ if (expected === "*") {
37
+ const nextExpected = getExpected();
38
+ if (handleCase(nextExpected) !== handleCase(actual)) {
39
+ matchAny = true;
40
+ i--;
41
+ }
42
+ } else if (expected === "+") {
43
+ matchAny = true;
44
+ } else if (handleCase(expected) === handleCase(actual)) {
45
+ matchAny = false;
46
+ } else if (matchAny) {
47
+ i--;
48
+ } else {
49
+ addErrorDetailIf(
50
+ onError,
51
+ heading.startLine,
52
+ expected,
53
+ actual
54
+ );
55
+ hasError = true;
56
+ }
57
+ }
58
+ }
59
+ const extraHeadings = requiredHeadings.length - i;
60
+ if (
61
+ !hasError &&
62
+ ((extraHeadings > 1) ||
63
+ ((extraHeadings === 1) && (requiredHeadings[i] !== "*"))) &&
64
+ (anyHeadings || !requiredHeadings.every((heading) => heading === "*"))
65
+ ) {
66
+ addErrorContext(
67
+ onError,
68
+ params.lines.length,
69
+ requiredHeadings[i]
70
+ );
71
+ }
72
+ }
73
+ };
@@ -0,0 +1,110 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf, escapeForRegExp, withinAnyRange } =
6
+ require("../helpers");
7
+ const { filterByPredicate, filterByTypes, parse } =
8
+ require("../helpers/micromark.cjs");
9
+
10
+ const ignoredChildTypes = new Set(
11
+ [ "codeFencedFence", "definition", "reference", "resource" ]
12
+ );
13
+
14
+ // eslint-disable-next-line jsdoc/valid-types
15
+ /** @type import("./markdownlint").Rule */
16
+ module.exports = {
17
+ "names": [ "MD044", "proper-names" ],
18
+ "description": "Proper names should have the correct capitalization",
19
+ "tags": [ "spelling" ],
20
+ "parser": "micromark",
21
+ "function": function MD044(params, onError) {
22
+ let names = params.config.names;
23
+ names = Array.isArray(names) ? names : [];
24
+ names.sort((a, b) => (b.length - a.length) || a.localeCompare(b));
25
+ if (names.length === 0) {
26
+ // Nothing to check; avoid doing any work
27
+ return;
28
+ }
29
+ const codeBlocks = params.config.code_blocks;
30
+ const includeCodeBlocks =
31
+ (codeBlocks === undefined) ? true : !!codeBlocks;
32
+ const htmlElements = params.config.html_elements;
33
+ const includeHtmlElements =
34
+ (htmlElements === undefined) ? true : !!htmlElements;
35
+ const scannedTypes = new Set([ "data" ]);
36
+ if (includeCodeBlocks) {
37
+ scannedTypes.add("codeFlowValue");
38
+ scannedTypes.add("codeTextData");
39
+ }
40
+ if (includeHtmlElements) {
41
+ scannedTypes.add("htmlFlowData");
42
+ scannedTypes.add("htmlTextData");
43
+ }
44
+ const contentTokens =
45
+ filterByPredicate(
46
+ params.parsers.micromark.tokens,
47
+ (token) => scannedTypes.has(token.type),
48
+ (token) => (
49
+ token.children.filter((t) => !ignoredChildTypes.has(t.type))
50
+ )
51
+ );
52
+ const exclusions = [];
53
+ const autoLinked = new Set();
54
+ for (const name of names) {
55
+ const escapedName = escapeForRegExp(name);
56
+ const startNamePattern = /^\W/.test(name) ? "" : "\\b_*";
57
+ const endNamePattern = /\W$/.test(name) ? "" : "_*\\b";
58
+ const namePattern =
59
+ `(${startNamePattern})(${escapedName})${endNamePattern}`;
60
+ const nameRe = new RegExp(namePattern, "gi");
61
+ for (const token of contentTokens) {
62
+ let match = null;
63
+ while ((match = nameRe.exec(token.text)) !== null) {
64
+ const [ , leftMatch, nameMatch ] = match;
65
+ const index = token.startColumn - 1 + match.index + leftMatch.length;
66
+ const length = nameMatch.length;
67
+ const lineIndex = token.startLine - 1;
68
+ if (
69
+ !withinAnyRange(exclusions, lineIndex, index, length) &&
70
+ !names.includes(nameMatch)
71
+ ) {
72
+ let urlRanges = [];
73
+ if (!autoLinked.has(token)) {
74
+ urlRanges = filterByTypes(
75
+ parse(token.text),
76
+ [ "literalAutolink" ]
77
+ ).map(
78
+ (t) => [
79
+ lineIndex,
80
+ token.startColumn - 1 + t.startColumn - 1,
81
+ t.endColumn - t.startColumn
82
+ ]
83
+ );
84
+ exclusions.push(...urlRanges);
85
+ autoLinked.add(token);
86
+ }
87
+ if (!withinAnyRange(urlRanges, lineIndex, index, length)) {
88
+ const column = index + 1;
89
+ addErrorDetailIf(
90
+ onError,
91
+ token.startLine,
92
+ name,
93
+ nameMatch,
94
+ undefined,
95
+ undefined,
96
+ [ column, length ],
97
+ {
98
+ "editColumn": column,
99
+ "deleteCount": length,
100
+ "insertText": name
101
+ }
102
+ );
103
+ }
104
+ }
105
+ exclusions.push([ lineIndex, index, length ]);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ };
@@ -0,0 +1,62 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
6
+ const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ const altRe = getHtmlAttributeRe("alt");
10
+
11
+ // eslint-disable-next-line jsdoc/valid-types
12
+ /** @type import("./markdownlint").Rule */
13
+ module.exports = {
14
+ "names": [ "MD045", "no-alt-text" ],
15
+ "description": "Images should have alternate text (alt text)",
16
+ "tags": [ "accessibility", "images" ],
17
+ "parser": "micromark",
18
+ "function": function MD045(params, onError) {
19
+ // Process Markdown images
20
+ const images = filterByTypesCached([ "image" ]);
21
+ for (const image of images) {
22
+ const labelTexts = filterByTypes(image.children, [ "labelText" ]);
23
+ if (labelTexts.some((labelText) => labelText.text.length === 0)) {
24
+ const range = (image.startLine === image.endLine) ?
25
+ [ image.startColumn, image.endColumn - image.startColumn ] :
26
+ undefined;
27
+ addError(
28
+ onError,
29
+ image.startLine,
30
+ undefined,
31
+ undefined,
32
+ range
33
+ );
34
+ }
35
+ }
36
+
37
+ // Process HTML images
38
+ const htmlTexts = filterByTypesCached([ "htmlText" ], true);
39
+ for (const htmlText of htmlTexts) {
40
+ const { startColumn, startLine, text } = htmlText;
41
+ const htmlTagInfo = getHtmlTagInfo(htmlText);
42
+ if (
43
+ htmlTagInfo &&
44
+ !htmlTagInfo.close &&
45
+ (htmlTagInfo.name.toLowerCase() === "img") &&
46
+ !altRe.test(text)
47
+ ) {
48
+ const range = [
49
+ startColumn,
50
+ text.replace(nextLinesRe, "").length
51
+ ];
52
+ addError(
53
+ onError,
54
+ startLine,
55
+ undefined,
56
+ undefined,
57
+ range
58
+ );
59
+ }
60
+ }
61
+ }
62
+ };
@@ -0,0 +1,34 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf } = require("../helpers");
6
+ const { filterByTypesCached } = require("./cache");
7
+
8
+ const tokenTypeToStyle = {
9
+ "codeFenced": "fenced",
10
+ "codeIndented": "indented"
11
+ };
12
+
13
+ // eslint-disable-next-line jsdoc/valid-types
14
+ /** @type import("./markdownlint").Rule */
15
+ module.exports = {
16
+ "names": [ "MD046", "code-block-style" ],
17
+ "description": "Code block style",
18
+ "tags": [ "code" ],
19
+ "parser": "micromark",
20
+ "function": function MD046(params, onError) {
21
+ let expectedStyle = String(params.config.style || "consistent");
22
+ for (const token of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
23
+ const { startLine, type } = token;
24
+ if (expectedStyle === "consistent") {
25
+ expectedStyle = tokenTypeToStyle[type];
26
+ }
27
+ addErrorDetailIf(
28
+ onError,
29
+ startLine,
30
+ expectedStyle,
31
+ tokenTypeToStyle[type]);
32
+ }
33
+ }
34
+ };
@@ -0,0 +1,31 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addError, isBlankLine } = require("../helpers");
6
+
7
+ // eslint-disable-next-line jsdoc/valid-types
8
+ /** @type import("./markdownlint").Rule */
9
+ module.exports = {
10
+ "names": [ "MD047", "single-trailing-newline" ],
11
+ "description": "Files should end with a single newline character",
12
+ "tags": [ "blank_lines" ],
13
+ "parser": "none",
14
+ "function": function MD047(params, onError) {
15
+ const lastLineNumber = params.lines.length;
16
+ const lastLine = params.lines[lastLineNumber - 1];
17
+ if (!isBlankLine(lastLine)) {
18
+ addError(
19
+ onError,
20
+ lastLineNumber,
21
+ undefined,
22
+ undefined,
23
+ [ lastLine.length, 1 ],
24
+ {
25
+ "insertText": "\n",
26
+ "editColumn": lastLine.length + 1
27
+ }
28
+ );
29
+ }
30
+ }
31
+ };
@@ -0,0 +1,39 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf, fencedCodeBlockStyleFor } = require("../helpers");
6
+ const { tokenIfType } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD048", "code-fence-style" ],
13
+ "description": "Code fence style",
14
+ "tags": [ "code" ],
15
+ "parser": "micromark",
16
+ "function": function MD048(params, onError) {
17
+ const style = String(params.config.style || "consistent");
18
+ let expectedStyle = style;
19
+ const codeFenceds = filterByTypesCached([ "codeFenced" ]);
20
+ for (const codeFenced of codeFenceds) {
21
+ const codeFencedFence = tokenIfType(codeFenced.children[0], "codeFencedFence");
22
+ if (codeFencedFence) {
23
+ const codeFencedFenceSequence = tokenIfType(codeFencedFence.children[0], "codeFencedFenceSequence");
24
+ if (codeFencedFenceSequence) {
25
+ const { startLine, text } = codeFencedFenceSequence;
26
+ if (expectedStyle === "consistent") {
27
+ expectedStyle = fencedCodeBlockStyleFor(text);
28
+ }
29
+ addErrorDetailIf(
30
+ onError,
31
+ startLine,
32
+ expectedStyle,
33
+ fencedCodeBlockStyleFor(text)
34
+ );
35
+ }
36
+ }
37
+ }
38
+ }
39
+ };