@alexlit/lint-kit 127.2.0 → 127.4.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 (142) hide show
  1. package/package.json +1 -1
  2. package/packages/config-eslint/package.json +3 -3
  3. package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +457 -0
  4. package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +93 -0
  5. package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
  6. package/packages/config-markdownlint/node_modules/markdownlint/README.md +1047 -0
  7. package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +7094 -0
  8. package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +388 -0
  9. package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
  10. package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
  11. package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2528 -0
  12. package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
  13. package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
  14. package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
  15. package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
  16. package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
  17. package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
  18. package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
  19. package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
  20. package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
  21. package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +58 -0
  22. package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
  23. package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
  24. package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
  25. package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
  26. package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
  27. package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
  28. package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
  29. package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +44 -0
  30. package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
  31. package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
  32. package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
  33. package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
  34. package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
  35. package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
  36. package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
  37. package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
  38. package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
  39. package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +55 -0
  40. package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
  41. package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
  42. package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
  43. package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
  44. package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
  45. package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
  46. package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
  47. package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
  48. package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
  49. package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +45 -0
  50. package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
  51. package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
  52. package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
  53. package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
  54. package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +35 -0
  55. package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +35 -0
  56. package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +87 -0
  57. package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
  58. package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
  59. package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
  60. package/packages/config-markdownlint/node_modules/markdownlint/doc/md055.md +54 -0
  61. package/packages/config-markdownlint/node_modules/markdownlint/doc/md056.md +37 -0
  62. package/packages/config-markdownlint/node_modules/markdownlint/doc/md058.md +48 -0
  63. package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
  64. package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +46 -0
  65. package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +793 -0
  66. package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +544 -0
  67. package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
  68. package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
  69. package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +70 -0
  70. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration-strict.d.ts +1185 -0
  71. package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +8 -0
  72. package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +15 -0
  73. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +488 -0
  74. package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1572 -0
  75. package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +31 -0
  76. package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +50 -0
  77. package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +86 -0
  78. package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +72 -0
  79. package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +88 -0
  80. package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +95 -0
  81. package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +78 -0
  82. package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +57 -0
  83. package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +43 -0
  84. package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +105 -0
  85. package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +54 -0
  86. package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +46 -0
  87. package/packages/config-markdownlint/node_modules/markdownlint/lib/md019-md021.js +80 -0
  88. package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +71 -0
  89. package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +106 -0
  90. package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +40 -0
  91. package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +48 -0
  92. package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +40 -0
  93. package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +49 -0
  94. package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +37 -0
  95. package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +42 -0
  96. package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +76 -0
  97. package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +60 -0
  98. package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +63 -0
  99. package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +66 -0
  100. package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +41 -0
  101. package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +100 -0
  102. package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +26 -0
  103. package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +51 -0
  104. package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +94 -0
  105. package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +100 -0
  106. package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +83 -0
  107. package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
  108. package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +37 -0
  109. package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +63 -0
  110. package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +73 -0
  111. package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +110 -0
  112. package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +62 -0
  113. package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +34 -0
  114. package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +31 -0
  115. package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +39 -0
  116. package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +103 -0
  117. package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +170 -0
  118. package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +42 -0
  119. package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +62 -0
  120. package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
  121. package/packages/config-markdownlint/node_modules/markdownlint/lib/md055.js +79 -0
  122. package/packages/config-markdownlint/node_modules/markdownlint/lib/md056.js +56 -0
  123. package/packages/config-markdownlint/node_modules/markdownlint/lib/md058.js +43 -0
  124. package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +74 -0
  125. package/packages/config-markdownlint/node_modules/markdownlint/package.json +105 -0
  126. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +307 -0
  127. package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +275 -0
  128. package/packages/config-markdownlint/node_modules/markdownlint/schema/ValidatingConfiguration.md +26 -0
  129. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema-strict.json +1819 -0
  130. package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1824 -0
  131. package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
  132. package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
  133. package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +27 -0
  134. package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
  135. package/packages/config-markdownlint/node_modules/markdownlint-micromark/LICENSE +21 -0
  136. package/packages/config-markdownlint/node_modules/markdownlint-micromark/README.md +10 -0
  137. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-browser.js +2 -0
  138. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark-html-browser.js +2 -0
  139. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.cjs +1 -0
  140. package/packages/config-markdownlint/node_modules/markdownlint-micromark/micromark.d.cts +1751 -0
  141. package/packages/config-markdownlint/node_modules/markdownlint-micromark/package.json +46 -0
  142. package/packages/config-markdownlint/package.json +2 -2
@@ -0,0 +1,105 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf } = require("../helpers");
6
+ const { getReferenceLinkImageData } = require("./cache");
7
+ const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark.cjs");
8
+ const { filterByTypesCached } = require("./cache");
9
+
10
+ const longLineRePrefix = "^.{";
11
+ const longLineRePostfixRelaxed = "}.*\\s.*$";
12
+ const longLineRePostfixStrict = "}.+$";
13
+ const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
14
+
15
+ // eslint-disable-next-line jsdoc/valid-types
16
+ /** @type import("./markdownlint").Rule */
17
+ module.exports = {
18
+ "names": [ "MD013", "line-length" ],
19
+ "description": "Line length",
20
+ "tags": [ "line_length" ],
21
+ "parser": "micromark",
22
+ "function": function MD013(params, onError) {
23
+ const lineLength = Number(params.config.line_length || 80);
24
+ const headingLineLength =
25
+ Number(params.config.heading_line_length || lineLength);
26
+ const codeLineLength =
27
+ Number(params.config.code_block_line_length || lineLength);
28
+ const strict = !!params.config.strict;
29
+ const stern = !!params.config.stern;
30
+ const longLineRePostfix =
31
+ (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed;
32
+ const longLineRe =
33
+ new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
34
+ const longHeadingLineRe =
35
+ new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix);
36
+ const longCodeLineRe =
37
+ new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix);
38
+ const codeBlocks = params.config.code_blocks;
39
+ const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
40
+ const tables = params.config.tables;
41
+ const includeTables = (tables === undefined) ? true : !!tables;
42
+ const headings = params.config.headings;
43
+ const includeHeadings = (headings === undefined) ? true : !!headings;
44
+ const headingLineNumbers = new Set();
45
+ for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
46
+ addRangeToSet(headingLineNumbers, heading.startLine, heading.endLine);
47
+ }
48
+ const codeBlockLineNumbers = new Set();
49
+ for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
50
+ addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
51
+ }
52
+ const tableLineNumbers = new Set();
53
+ for (const table of filterByTypesCached([ "table" ])) {
54
+ addRangeToSet(tableLineNumbers, table.startLine, table.endLine);
55
+ }
56
+ const linkLineNumbers = new Set();
57
+ for (const link of filterByTypesCached([ "autolink", "image", "link", "literalAutolink" ])) {
58
+ addRangeToSet(linkLineNumbers, link.startLine, link.endLine);
59
+ }
60
+ const paragraphDataLineNumbers = new Set();
61
+ for (const paragraph of filterByTypesCached([ "paragraph" ])) {
62
+ for (const data of getDescendantsByType(paragraph, [ "data" ])) {
63
+ addRangeToSet(paragraphDataLineNumbers, data.startLine, data.endLine);
64
+ }
65
+ }
66
+ const linkOnlyLineNumbers = new Set();
67
+ for (const lineNumber of linkLineNumbers) {
68
+ if (!paragraphDataLineNumbers.has(lineNumber)) {
69
+ linkOnlyLineNumbers.add(lineNumber);
70
+ }
71
+ }
72
+ const definitionLineIndices = new Set(getReferenceLinkImageData().definitionLineIndices);
73
+ for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
74
+ const line = params.lines[lineIndex];
75
+ const lineNumber = lineIndex + 1;
76
+ const isHeading = headingLineNumbers.has(lineNumber);
77
+ const inCode = codeBlockLineNumbers.has(lineNumber);
78
+ const inTable = tableLineNumbers.has(lineNumber);
79
+ const length = inCode ?
80
+ codeLineLength :
81
+ (isHeading ? headingLineLength : lineLength);
82
+ const lengthRe = inCode ?
83
+ longCodeLineRe :
84
+ (isHeading ? longHeadingLineRe : longLineRe);
85
+ if ((includeCodeBlocks || !inCode) &&
86
+ (includeTables || !inTable) &&
87
+ (includeHeadings || !isHeading) &&
88
+ !definitionLineIndices.has(lineIndex) &&
89
+ (strict ||
90
+ (!(stern && sternModeRe.test(line)) &&
91
+ !linkOnlyLineNumbers.has(lineNumber))) &&
92
+ lengthRe.test(line)) {
93
+ addErrorDetailIf(
94
+ onError,
95
+ lineNumber,
96
+ length,
97
+ line.length,
98
+ undefined,
99
+ undefined,
100
+ [ length + 1, line.length - length ]
101
+ );
102
+ }
103
+ }
104
+ }
105
+ };
@@ -0,0 +1,54 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { filterByTypes } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ const dollarCommandRe = /^(\s*)(\$\s+)/;
10
+
11
+ // eslint-disable-next-line jsdoc/valid-types
12
+ /** @type import("./markdownlint").Rule */
13
+ module.exports = {
14
+ "names": [ "MD014", "commands-show-output" ],
15
+ "description": "Dollar signs used before commands without showing output",
16
+ "tags": [ "code" ],
17
+ "parser": "micromark",
18
+ "function": function MD014(params, onError) {
19
+ for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
20
+ const codeFlowValues = filterByTypes(
21
+ codeBlock.children,
22
+ [ "codeFlowValue" ]
23
+ );
24
+ const dollarMatches = codeFlowValues.
25
+ map((codeFlowValue) => ({
26
+ "result": codeFlowValue.text.match(dollarCommandRe),
27
+ "startColumn": codeFlowValue.startColumn,
28
+ "startLine": codeFlowValue.startLine,
29
+ "text": codeFlowValue.text
30
+ })).
31
+ filter((dollarMatch) => dollarMatch.result);
32
+ if (dollarMatches.length === codeFlowValues.length) {
33
+ for (const dollarMatch of dollarMatches) {
34
+ // @ts-ignore
35
+ const column = dollarMatch.startColumn + dollarMatch.result[1].length;
36
+ // @ts-ignore
37
+ const length = dollarMatch.result[2].length;
38
+ addErrorContext(
39
+ onError,
40
+ dollarMatch.startLine,
41
+ dollarMatch.text,
42
+ undefined,
43
+ undefined,
44
+ [ column, length ],
45
+ {
46
+ "editColumn": column,
47
+ "deleteCount": length
48
+ }
49
+ );
50
+ }
51
+ }
52
+ }
53
+ }
54
+ };
@@ -0,0 +1,46 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { addRangeToSet } = 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": [ "MD018", "no-missing-space-atx" ],
13
+ "description": "No space after hash on atx style heading",
14
+ "tags": [ "headings", "atx", "spaces" ],
15
+ "parser": "micromark",
16
+ "function": function MD018(params, onError) {
17
+ const { lines } = params;
18
+ const ignoreBlockLineNumbers = new Set();
19
+ for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "htmlFlow" ])) {
20
+ addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
21
+ }
22
+ for (const [ lineIndex, line ] of lines.entries()) {
23
+ if (
24
+ !ignoreBlockLineNumbers.has(lineIndex + 1) &&
25
+ /^#+[^# \t]/.test(line) &&
26
+ !/#\s*$/.test(line) &&
27
+ !line.startsWith("#️⃣")
28
+ ) {
29
+ // @ts-ignore
30
+ const hashCount = /^#+/.exec(line)[0].length;
31
+ addErrorContext(
32
+ onError,
33
+ lineIndex + 1,
34
+ line.trim(),
35
+ undefined,
36
+ undefined,
37
+ [ 1, hashCount + 1 ],
38
+ {
39
+ "editColumn": hashCount + 1,
40
+ "insertText": " "
41
+ }
42
+ );
43
+ }
44
+ }
45
+ }
46
+ };
@@ -0,0 +1,80 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers/helpers");
6
+ const { getHeadingStyle } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ /**
10
+ * Validate heading sequence and whitespace length at start or end.
11
+ *
12
+ * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
13
+ * @param {import("./markdownlint").MicromarkToken} heading ATX heading token.
14
+ * @param {number} delta Direction to scan.
15
+ * @returns {void}
16
+ */
17
+ function validateHeadingSpaces(onError, heading, delta) {
18
+ const { children, startLine, text } = heading;
19
+ let index = (delta > 0) ? 0 : (children.length - 1);
20
+ while (
21
+ children[index] &&
22
+ (children[index].type !== "atxHeadingSequence")
23
+ ) {
24
+ index += delta;
25
+ }
26
+ const headingSequence = children[index];
27
+ const whitespace = children[index + delta];
28
+ if (
29
+ (headingSequence?.type === "atxHeadingSequence") &&
30
+ (whitespace?.type === "whitespace") &&
31
+ (whitespace.text.length > 1)
32
+ ) {
33
+ const column = whitespace.startColumn + 1;
34
+ const length = whitespace.endColumn - column;
35
+ addErrorContext(
36
+ onError,
37
+ startLine,
38
+ text.trim(),
39
+ delta > 0,
40
+ delta < 0,
41
+ [ column, length ],
42
+ {
43
+ "editColumn": column,
44
+ "deleteCount": length
45
+ }
46
+ );
47
+ }
48
+ }
49
+
50
+ // eslint-disable-next-line jsdoc/valid-types
51
+ /** @type import("./markdownlint").Rule[] */
52
+ module.exports = [
53
+ {
54
+ "names": [ "MD019", "no-multiple-space-atx" ],
55
+ "description": "Multiple spaces after hash on atx style heading",
56
+ "tags": [ "headings", "atx", "spaces" ],
57
+ "parser": "micromark",
58
+ "function": function MD019(params, onError) {
59
+ const atxHeadings = filterByTypesCached([ "atxHeading" ])
60
+ .filter((heading) => getHeadingStyle(heading) === "atx");
61
+ for (const atxHeading of atxHeadings) {
62
+ validateHeadingSpaces(onError, atxHeading, 1);
63
+ }
64
+ }
65
+ },
66
+ {
67
+ "names": [ "MD021", "no-multiple-space-closed-atx" ],
68
+ "description": "Multiple spaces inside hashes on closed atx style heading",
69
+ "tags": [ "headings", "atx_closed", "spaces" ],
70
+ "parser": "micromark",
71
+ "function": function MD021(params, onError) {
72
+ const atxClosedHeadings = filterByTypesCached([ "atxHeading" ])
73
+ .filter((heading) => getHeadingStyle(heading) === "atx_closed");
74
+ for (const atxClosedHeading of atxClosedHeadings) {
75
+ validateHeadingSpaces(onError, atxClosedHeading, 1);
76
+ validateHeadingSpaces(onError, atxClosedHeading, -1);
77
+ }
78
+ }
79
+ }
80
+ ];
@@ -0,0 +1,71 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { addRangeToSet } = 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": [ "MD020", "no-missing-space-closed-atx" ],
13
+ "description": "No space inside hashes on closed atx style heading",
14
+ "tags": [ "headings", "atx_closed", "spaces" ],
15
+ "parser": "micromark",
16
+ "function": function MD020(params, onError) {
17
+ const { lines } = params;
18
+ const ignoreBlockLineNumbers = new Set();
19
+ for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "htmlFlow" ])) {
20
+ addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
21
+ }
22
+ for (const [ lineIndex, line ] of lines.entries()) {
23
+ if (!ignoreBlockLineNumbers.has(lineIndex + 1)) {
24
+ const match =
25
+ /^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
26
+ if (match) {
27
+ const [
28
+ ,
29
+ leftHash,
30
+ { "length": leftSpaceLength },
31
+ content,
32
+ { "length": rightSpaceLength },
33
+ rightEscape,
34
+ rightHash,
35
+ { "length": trailSpaceLength }
36
+ ] = match;
37
+ const leftHashLength = leftHash.length;
38
+ const rightHashLength = rightHash.length;
39
+ const left = !leftSpaceLength;
40
+ const right = !rightSpaceLength || !!rightEscape;
41
+ const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : "";
42
+ if (left || right) {
43
+ const range = left ?
44
+ [
45
+ 1,
46
+ leftHashLength + 1
47
+ ] :
48
+ [
49
+ line.length - trailSpaceLength - rightHashLength,
50
+ rightHashLength + 1
51
+ ];
52
+ addErrorContext(
53
+ onError,
54
+ lineIndex + 1,
55
+ line.trim(),
56
+ left,
57
+ right,
58
+ range,
59
+ {
60
+ "editColumn": 1,
61
+ "deleteCount": line.length,
62
+ "insertText":
63
+ `${leftHash} ${content} ${rightEscapeReplacement}${rightHash}`
64
+ }
65
+ );
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ };
@@ -0,0 +1,106 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } = require("../helpers");
6
+ const { getHeadingLevel } = require("../helpers/micromark.cjs");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ const defaultLines = 1;
10
+
11
+ const getLinesFunction = (linesParam) => {
12
+ if (Array.isArray(linesParam)) {
13
+ const linesArray = new Array(6).fill(defaultLines);
14
+ for (const [ index, value ] of [ ...linesParam.entries() ].slice(0, 6)) {
15
+ linesArray[index] = value;
16
+ }
17
+ return (heading) => linesArray[getHeadingLevel(heading) - 1];
18
+ }
19
+ // Coerce linesParam to a number
20
+ const lines = (linesParam === undefined) ? defaultLines : Number(linesParam);
21
+ return () => lines;
22
+ };
23
+
24
+ const getBlockQuote = (str, count) => (
25
+ (str || "")
26
+ .match(blockquotePrefixRe)[0]
27
+ .trimEnd()
28
+ // eslint-disable-next-line unicorn/prefer-spread
29
+ .concat("\n")
30
+ .repeat(count)
31
+ );
32
+
33
+ // eslint-disable-next-line jsdoc/valid-types
34
+ /** @type import("./markdownlint").Rule */
35
+ module.exports = {
36
+ "names": [ "MD022", "blanks-around-headings" ],
37
+ "description": "Headings should be surrounded by blank lines",
38
+ "tags": [ "headings", "blank_lines" ],
39
+ "parser": "micromark",
40
+ "function": function MD022(params, onError) {
41
+ const getLinesAbove = getLinesFunction(params.config.lines_above);
42
+ const getLinesBelow = getLinesFunction(params.config.lines_below);
43
+ const { lines } = params;
44
+ for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
45
+ const { startLine, endLine } = heading;
46
+ const line = lines[startLine - 1].trim();
47
+
48
+ // Check lines above
49
+ const linesAbove = getLinesAbove(heading);
50
+ if (linesAbove >= 0) {
51
+ let actualAbove = 0;
52
+ for (
53
+ let i = 0;
54
+ (i < linesAbove) && isBlankLine(lines[startLine - 2 - i]);
55
+ i++
56
+ ) {
57
+ actualAbove++;
58
+ }
59
+ addErrorDetailIf(
60
+ onError,
61
+ startLine,
62
+ linesAbove,
63
+ actualAbove,
64
+ "Above",
65
+ line,
66
+ undefined,
67
+ {
68
+ "insertText": getBlockQuote(
69
+ lines[startLine - 2],
70
+ linesAbove - actualAbove
71
+ )
72
+ }
73
+ );
74
+ }
75
+
76
+ // Check lines below
77
+ const linesBelow = getLinesBelow(heading);
78
+ if (linesBelow >= 0) {
79
+ let actualBelow = 0;
80
+ for (
81
+ let i = 0;
82
+ (i < linesBelow) && isBlankLine(lines[endLine + i]);
83
+ i++
84
+ ) {
85
+ actualBelow++;
86
+ }
87
+ addErrorDetailIf(
88
+ onError,
89
+ startLine,
90
+ linesBelow,
91
+ actualBelow,
92
+ "Below",
93
+ line,
94
+ undefined,
95
+ {
96
+ "lineNumber": endLine + 1,
97
+ "insertText": getBlockQuote(
98
+ lines[endLine],
99
+ linesBelow - actualBelow
100
+ )
101
+ }
102
+ );
103
+ }
104
+ }
105
+ }
106
+ };
@@ -0,0 +1,40 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { filterByTypesCached } = require("./cache");
7
+
8
+ // eslint-disable-next-line jsdoc/valid-types
9
+ /** @type import("./markdownlint").Rule */
10
+ module.exports = {
11
+ "names": [ "MD023", "heading-start-left" ],
12
+ "description": "Headings must start at the beginning of the line",
13
+ "tags": [ "headings", "spaces" ],
14
+ "parser": "micromark",
15
+ "function": function MD023(params, onError) {
16
+ const headings = filterByTypesCached([ "atxHeading", "linePrefix", "setextHeading" ]);
17
+ for (let i = 0; i < headings.length - 1; i++) {
18
+ if (
19
+ (headings[i].type === "linePrefix") &&
20
+ (headings[i + 1].type !== "linePrefix") &&
21
+ (headings[i].startLine === headings[i + 1].startLine)
22
+ ) {
23
+ const { endColumn, startColumn, startLine } = headings[i];
24
+ const length = endColumn - startColumn;
25
+ addErrorContext(
26
+ onError,
27
+ startLine,
28
+ params.lines[startLine - 1],
29
+ true,
30
+ false,
31
+ [ startColumn, length ],
32
+ {
33
+ "editColumn": startColumn,
34
+ "deleteCount": length
35
+ }
36
+ );
37
+ }
38
+ }
39
+ }
40
+ };
@@ -0,0 +1,48 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = 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": [ "MD024", "no-duplicate-heading" ],
13
+ "description": "Multiple headings with the same content",
14
+ "tags": [ "headings" ],
15
+ "parser": "micromark",
16
+ "function": function MD024(params, onError) {
17
+ const siblingsOnly = !!params.config.siblings_only || false;
18
+ const knownContents = [ null, [] ];
19
+ let lastLevel = 1;
20
+ let knownContent = knownContents[lastLevel];
21
+ for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
22
+ const headingText = getHeadingText(heading);
23
+ if (siblingsOnly) {
24
+ const newLevel = getHeadingLevel(heading);
25
+ while (lastLevel < newLevel) {
26
+ lastLevel++;
27
+ knownContents[lastLevel] = [];
28
+ }
29
+ while (lastLevel > newLevel) {
30
+ knownContents[lastLevel] = [];
31
+ lastLevel--;
32
+ }
33
+ knownContent = knownContents[newLevel];
34
+ }
35
+ // @ts-ignore
36
+ if (knownContent.includes(headingText)) {
37
+ addErrorContext(
38
+ onError,
39
+ heading.startLine,
40
+ headingText.trim()
41
+ );
42
+ } else {
43
+ // @ts-ignore
44
+ knownContent.push(headingText);
45
+ }
46
+ }
47
+ }
48
+ };
@@ -0,0 +1,40 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext, frontMatterHasTitle } = 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": [ "MD025", "single-title", "single-h1" ],
13
+ "description": "Multiple top-level headings in the same document",
14
+ "tags": [ "headings" ],
15
+ "parser": "micromark",
16
+ "function": function MD025(params, onError) {
17
+ const level = Number(params.config.level || 1);
18
+ const foundFrontMatterTitle =
19
+ frontMatterHasTitle(
20
+ params.frontMatterLines,
21
+ params.config.front_matter_title
22
+ );
23
+ let hasTopLevelHeading = false;
24
+ for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
25
+ const headingLevel = getHeadingLevel(heading);
26
+ if (headingLevel === level) {
27
+ if (hasTopLevelHeading || foundFrontMatterTitle) {
28
+ const headingText = getHeadingText(heading);
29
+ addErrorContext(
30
+ onError,
31
+ heading.startLine,
32
+ headingText
33
+ );
34
+ } else if (heading.startLine === 1) {
35
+ hasTopLevelHeading = true;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ };
@@ -0,0 +1,49 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
6
+ endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers");
7
+ const { filterByTypesCached } = require("./cache");
8
+
9
+ // eslint-disable-next-line jsdoc/valid-types
10
+ /** @type import("./markdownlint").Rule */
11
+ module.exports = {
12
+ "names": [ "MD026", "no-trailing-punctuation" ],
13
+ "description": "Trailing punctuation in heading",
14
+ "tags": [ "headings" ],
15
+ "parser": "micromark",
16
+ "function": function MD026(params, onError) {
17
+ let punctuation = params.config.punctuation;
18
+ punctuation = String(
19
+ (punctuation === undefined) ? allPunctuationNoQuestion : punctuation
20
+ );
21
+ const trailingPunctuationRe =
22
+ new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
23
+ const headings = filterByTypesCached([ "atxHeadingText", "setextHeadingText" ]);
24
+ for (const heading of headings) {
25
+ const { endColumn, endLine, text } = heading;
26
+ const match = trailingPunctuationRe.exec(text);
27
+ if (
28
+ match &&
29
+ !endOfLineHtmlEntityRe.test(text) &&
30
+ !endOfLineGemojiCodeRe.test(text)
31
+ ) {
32
+ const fullMatch = match[0];
33
+ const length = fullMatch.length;
34
+ const column = endColumn - length;
35
+ addError(
36
+ onError,
37
+ endLine,
38
+ `Punctuation: '${fullMatch}'`,
39
+ undefined,
40
+ [ column, length ],
41
+ {
42
+ "editColumn": column,
43
+ "deleteCount": length
44
+ }
45
+ );
46
+ }
47
+ }
48
+ }
49
+ };
@@ -0,0 +1,37 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { addErrorContext } = require("../helpers");
6
+ const { filterByTypesCached } = require("./cache");
7
+
8
+ // eslint-disable-next-line jsdoc/valid-types
9
+ /** @type import("./markdownlint").Rule */
10
+ module.exports = {
11
+ "names": ["MD027", "no-multiple-space-blockquote"],
12
+ "description": "Multiple spaces after blockquote symbol",
13
+ "tags": ["blockquote", "whitespace", "indentation"],
14
+ "parser": "micromark",
15
+ "function": function MD027(params, onError) {
16
+ for (const token of filterByTypesCached([ "linePrefix" ])) {
17
+ const siblings = token.parent?.children || params.parsers.micromark.tokens;
18
+ if (siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") {
19
+ const { startColumn, startLine, text } = token;
20
+ const { length } = text;
21
+ const line = params.lines[startLine - 1];
22
+ addErrorContext(
23
+ onError,
24
+ startLine,
25
+ line,
26
+ undefined,
27
+ undefined,
28
+ [ startColumn, length ],
29
+ {
30
+ "editColumn": startColumn,
31
+ "deleteCount": length
32
+ }
33
+ );
34
+ }
35
+ }
36
+ }
37
+ };