markdownlint 0.36.1 → 0.37.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 (84) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +70 -117
  3. package/doc/CustomRules.md +6 -6
  4. package/helpers/README.md +2 -2
  5. package/helpers/{helpers.js → helpers.cjs} +15 -6
  6. package/helpers/micromark-helpers.cjs +5 -3
  7. package/helpers/package.json +2 -5
  8. package/lib/{cache.js → cache.mjs} +9 -17
  9. package/lib/configuration-strict.d.ts +104 -104
  10. package/lib/configuration.d.ts +1 -1
  11. package/lib/{constants.js → constants.mjs} +4 -6
  12. package/lib/exports-async.d.mts +1 -0
  13. package/lib/exports-async.mjs +3 -0
  14. package/lib/exports-promise.d.mts +1 -0
  15. package/lib/exports-promise.mjs +3 -0
  16. package/lib/exports-sync.d.mts +1 -0
  17. package/lib/exports-sync.mjs +3 -0
  18. package/lib/exports.d.mts +28 -0
  19. package/lib/exports.mjs +31 -0
  20. package/lib/markdownit.cjs +9 -5
  21. package/lib/{markdownlint.d.ts → markdownlint.d.mts} +66 -76
  22. package/lib/{markdownlint.js → markdownlint.mjs} +69 -75
  23. package/lib/{md001.js → md001.mjs} +5 -8
  24. package/lib/{md003.js → md003.mjs} +5 -8
  25. package/lib/{md004.js → md004.mjs} +6 -9
  26. package/lib/{md005.js → md005.mjs} +4 -7
  27. package/lib/{md007.js → md007.mjs} +8 -13
  28. package/lib/{md009.js → md009.mjs} +5 -8
  29. package/lib/{md010.js → md010.mjs} +7 -11
  30. package/lib/{md011.js → md011.mjs} +7 -11
  31. package/lib/{md012.js → md012.mjs} +5 -8
  32. package/lib/{md013.js → md013.mjs} +8 -9
  33. package/lib/{md014.js → md014.mjs} +4 -7
  34. package/lib/{md018.js → md018.mjs} +5 -8
  35. package/lib/{md019-md021.js → md019-md021.mjs} +7 -10
  36. package/lib/{md020.js → md020.mjs} +5 -8
  37. package/lib/{md022.js → md022.mjs} +5 -8
  38. package/lib/{md023.js → md023.mjs} +4 -7
  39. package/lib/{md024.js → md024.mjs} +5 -8
  40. package/lib/{md025.js → md025.mjs} +5 -8
  41. package/lib/{md026.js → md026.mjs} +5 -8
  42. package/lib/{md027.js → md027.mjs} +12 -9
  43. package/lib/{md028.js → md028.mjs} +4 -7
  44. package/lib/{md029.js → md029.mjs} +6 -9
  45. package/lib/{md030.js → md030.mjs} +4 -7
  46. package/lib/{md031.js → md031.mjs} +7 -10
  47. package/lib/{md032.js → md032.mjs} +5 -8
  48. package/lib/{md033.js → md033.mjs} +5 -8
  49. package/lib/{md034.js → md034.mjs} +5 -6
  50. package/lib/{md035.js → md035.mjs} +4 -7
  51. package/lib/{md036.js → md036.mjs} +6 -9
  52. package/lib/{md037.js → md037.mjs} +4 -7
  53. package/lib/{md038.js → md038.mjs} +5 -8
  54. package/lib/{md039.js → md039.mjs} +9 -12
  55. package/lib/{md040.js → md040.mjs} +5 -8
  56. package/lib/{md041.js → md041.mjs} +4 -8
  57. package/lib/{md042.js → md042.mjs} +5 -8
  58. package/lib/{md043.js → md043.mjs} +5 -8
  59. package/lib/{md044.js → md044.mjs} +8 -11
  60. package/lib/{md045.js → md045.mjs} +5 -8
  61. package/lib/{md046.js → md046.mjs} +4 -7
  62. package/lib/{md047.js → md047.mjs} +3 -6
  63. package/lib/{md048.js → md048.mjs} +5 -8
  64. package/lib/{md049-md050.js → md049-md050.mjs} +8 -11
  65. package/lib/{md051.js → md051.mjs} +8 -12
  66. package/lib/{md052.js → md052.mjs} +4 -7
  67. package/lib/{md053.js → md053.mjs} +4 -7
  68. package/lib/{md054.js → md054.mjs} +5 -8
  69. package/lib/{md055.js → md055.mjs} +6 -7
  70. package/lib/{md056.js → md056.mjs} +7 -8
  71. package/lib/{md058.js → md058.mjs} +6 -7
  72. package/{helpers/micromark-parse.cjs → lib/micromark-parse.mjs} +29 -33
  73. package/lib/micromark-types.d.mts +11 -0
  74. package/lib/rules.mjs +118 -0
  75. package/lib/types.d.mts +12 -0
  76. package/package.json +36 -32
  77. package/schema/.markdownlint.jsonc +51 -51
  78. package/schema/.markdownlint.yaml +51 -51
  79. package/schema/markdownlint-config-schema-strict.json +106 -106
  80. package/schema/markdownlint-config-schema.json +106 -106
  81. package/demo/markdownlint-browser.js +0 -7138
  82. package/helpers/test.cjs +0 -28
  83. package/lib/rules.js +0 -74
  84. /package/helpers/{shared.js → shared.cjs} +0 -0
@@ -1,18 +1,15 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorDetailIf, escapeForRegExp, hasOverlap } = require("../helpers");
6
- const { filterByPredicate, filterByTypes } = require("../helpers/micromark-helpers.cjs");
7
- const { parse } = require("../helpers/micromark-parse.cjs");
3
+ import { addErrorDetailIf, escapeForRegExp, hasOverlap } from "../helpers/helpers.cjs";
4
+ import { filterByPredicate, filterByTypes } from "../helpers/micromark-helpers.cjs";
5
+ import { parse } from "./micromark-parse.mjs";
8
6
 
9
7
  const ignoredChildTypes = new Set(
10
8
  [ "codeFencedFence", "definition", "reference", "resource" ]
11
9
  );
12
10
 
13
- // eslint-disable-next-line jsdoc/valid-types
14
- /** @type import("./markdownlint").Rule */
15
- module.exports = {
11
+ /** @type {import("markdownlint").Rule} */
12
+ export default {
16
13
  "names": [ "MD044", "proper-names" ],
17
14
  "description": "Proper names should have the correct capitalization",
18
15
  "tags": [ "spelling" ],
@@ -48,7 +45,7 @@ module.exports = {
48
45
  token.children.filter((t) => !ignoredChildTypes.has(t.type))
49
46
  )
50
47
  );
51
- /** @type {import("../helpers").FileRange[]} */
48
+ /** @type {import("../helpers/helpers.cjs").FileRange[]} */
52
49
  const exclusions = [];
53
50
  const scannedTokens = new Set();
54
51
  for (const name of names) {
@@ -64,7 +61,7 @@ module.exports = {
64
61
  const column = token.startColumn + match.index + leftMatch.length;
65
62
  const length = nameMatch.length;
66
63
  const lineNumber = token.startLine;
67
- /** @type {import("../helpers").FileRange} */
64
+ /** @type {import("../helpers/helpers.cjs").FileRange} */
68
65
  const nameRange = {
69
66
  "startLine": lineNumber,
70
67
  "startColumn": column,
@@ -75,7 +72,7 @@ module.exports = {
75
72
  !names.includes(nameMatch) &&
76
73
  !exclusions.some((exclusion) => hasOverlap(exclusion, nameRange))
77
74
  ) {
78
- /** @type {import("../helpers").FileRange[]} */
75
+ /** @type {import("../helpers/helpers.cjs").FileRange[]} */
79
76
  let autolinkRanges = [];
80
77
  if (!scannedTokens.has(token)) {
81
78
  autolinkRanges = filterByTypes(parse(token.text), [ "literalAutolink" ])
@@ -1,16 +1,13 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
6
- const { getHtmlTagInfo, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
- const { filterByTypesCached } = require("./cache");
3
+ import { addError, getHtmlAttributeRe, nextLinesRe } from "../helpers/helpers.cjs";
4
+ import { getHtmlTagInfo, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
+ import { filterByTypesCached } from "./cache.mjs";
8
6
 
9
7
  const altRe = getHtmlAttributeRe("alt");
10
8
 
11
- // eslint-disable-next-line jsdoc/valid-types
12
- /** @type import("./markdownlint").Rule */
13
- module.exports = {
9
+ /** @type {import("markdownlint").Rule} */
10
+ export default {
14
11
  "names": [ "MD045", "no-alt-text" ],
15
12
  "description": "Images should have alternate text (alt text)",
16
13
  "tags": [ "accessibility", "images" ],
@@ -1,18 +1,15 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorDetailIf } = require("../helpers");
6
- const { filterByTypesCached } = require("./cache");
3
+ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
+ import { filterByTypesCached } from "./cache.mjs";
7
5
 
8
6
  const tokenTypeToStyle = {
9
7
  "codeFenced": "fenced",
10
8
  "codeIndented": "indented"
11
9
  };
12
10
 
13
- // eslint-disable-next-line jsdoc/valid-types
14
- /** @type import("./markdownlint").Rule */
15
- module.exports = {
11
+ /** @type {import("markdownlint").Rule} */
12
+ export default {
16
13
  "names": [ "MD046", "code-block-style" ],
17
14
  "description": "Code block style",
18
15
  "tags": [ "code" ],
@@ -1,12 +1,9 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
3
+ import { addError, isBlankLine } from "../helpers/helpers.cjs";
4
4
 
5
- const { addError, isBlankLine } = require("../helpers");
6
-
7
- // eslint-disable-next-line jsdoc/valid-types
8
- /** @type import("./markdownlint").Rule */
9
- module.exports = {
5
+ /** @type {import("markdownlint").Rule} */
6
+ export default {
10
7
  "names": [ "MD047", "single-trailing-newline" ],
11
8
  "description": "Files should end with a single newline character",
12
9
  "tags": [ "blank_lines" ],
@@ -1,10 +1,8 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorDetailIf } = require("../helpers");
6
- const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
- const { filterByTypesCached } = require("./cache");
3
+ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
+ import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
+ import { filterByTypesCached } from "./cache.mjs";
8
6
 
9
7
  /**
10
8
  * Return the string representation of a fence markup character.
@@ -21,9 +19,8 @@ function fencedCodeBlockStyleFor(markup) {
21
19
  }
22
20
  };
23
21
 
24
- // eslint-disable-next-line jsdoc/valid-types
25
- /** @type import("./markdownlint").Rule */
26
- module.exports = {
22
+ /** @type {import("markdownlint").Rule} */
23
+ export default {
27
24
  "names": [ "MD048", "code-fence-style" ],
28
25
  "description": "Code fence style",
29
26
  "tags": [ "code" ],
@@ -1,9 +1,7 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addError } = require("../helpers");
6
- const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
3
+ import { addError } from "../helpers/helpers.cjs";
4
+ import { filterByPredicate, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
7
5
 
8
6
  const intrawordRe = /^\w$/;
9
7
 
@@ -23,10 +21,10 @@ function emphasisOrStrongStyleFor(markup) {
23
21
  };
24
22
 
25
23
  /**
26
- * @param {import("./markdownlint").RuleParams} params Rule parameters.
27
- * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
28
- * @param {import("markdownlint-micromark").TokenType} type Token type.
29
- * @param {import("markdownlint-micromark").TokenType} typeSequence Token sequence type.
24
+ * @param {import("markdownlint").RuleParams} params Rule parameters.
25
+ * @param {import("markdownlint").RuleOnError} onError Error-reporting callback.
26
+ * @param {import("micromark-util-types").TokenType} type Token type.
27
+ * @param {import("micromark-util-types").TokenType} typeSequence Token sequence type.
30
28
  * @param {"*" | "**"} asterisk Asterisk kind.
31
29
  * @param {"_" | "__"} underline Underline kind.
32
30
  * @param {"asterisk" | "consistent" | "underscore"} style Style string.
@@ -78,9 +76,8 @@ const impl =
78
76
  }
79
77
  };
80
78
 
81
- // eslint-disable-next-line jsdoc/valid-types
82
- /** @type import("./markdownlint").Rule[] */
83
- module.exports = [
79
+ /** @type {import("markdownlint").Rule[]} */
80
+ export default [
84
81
  {
85
82
  "names": [ "MD049", "emphasis-style" ],
86
83
  "description": "Emphasis style",
@@ -1,10 +1,8 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addError, getHtmlAttributeRe } = require("../helpers");
6
- const { filterByPredicate, filterByTypes, getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
7
- const { filterByTypesCached } = require("./cache");
3
+ import { addError, getHtmlAttributeRe } from "../helpers/helpers.cjs";
4
+ import { filterByPredicate, filterByTypes, getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
5
+ import { filterByTypesCached } from "./cache.mjs";
8
6
 
9
7
  // Regular expression for identifying HTML anchor names
10
8
  const idRe = getHtmlAttributeRe("id");
@@ -22,7 +20,7 @@ const tokensInclude = new Set(
22
20
  * Converts a Markdown heading into an HTML fragment according to the rules
23
21
  * used by GitHub.
24
22
  *
25
- * @param {import("../helpers/micromark-helpers.cjs").Token} headingText Heading text token.
23
+ * @param {import("markdownlint").MicromarkToken} headingText Heading text token.
26
24
  * @returns {string} Fragment string for heading.
27
25
  */
28
26
  function convertHeadingToHTMLFragment(headingText) {
@@ -51,7 +49,7 @@ function convertHeadingToHTMLFragment(headingText) {
51
49
  /**
52
50
  * Unescapes the text of a String-type micromark Token.
53
51
  *
54
- * @param {import("../helpers/micromark-helpers.cjs").Token} token String-type micromark Token.
52
+ * @param {import("markdownlint").MicromarkToken} token String-type micromark Token.
55
53
  * @returns {string} Unescaped token text.
56
54
  */
57
55
  function unescapeStringTokenText(token) {
@@ -60,9 +58,8 @@ function unescapeStringTokenText(token) {
60
58
  .join("");
61
59
  }
62
60
 
63
- // eslint-disable-next-line jsdoc/valid-types
64
- /** @type import("./markdownlint").Rule */
65
- module.exports = {
61
+ /** @type {import("markdownlint").Rule} */
62
+ export default {
66
63
  "names": [ "MD051", "link-fragments" ],
67
64
  "description": "Link fragments should be valid",
68
65
  "tags": [ "links" ],
@@ -104,8 +101,7 @@ module.exports = {
104
101
  }
105
102
 
106
103
  // Process link and definition fragments
107
- // eslint-disable-next-line jsdoc/valid-types
108
- /** @type import("../helpers/micromark-helpers.cjs").TokenType[][] */
104
+ /** @type {import("markdownlint").MicromarkTokenType[][]} */
109
105
  const parentChilds = [
110
106
  [ "link", "resourceDestinationString" ],
111
107
  [ "definition", "definitionDestinationString" ]
@@ -1,13 +1,10 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
3
+ import { addError } from "../helpers/helpers.cjs";
4
+ import { getReferenceLinkImageData } from "./cache.mjs";
4
5
 
5
- const { addError } = require("../helpers");
6
- const { getReferenceLinkImageData } = require("./cache");
7
-
8
- // eslint-disable-next-line jsdoc/valid-types
9
- /** @type import("./markdownlint").Rule */
10
- module.exports = {
6
+ /** @type {import("markdownlint").Rule} */
7
+ export default {
11
8
  "names": [ "MD052", "reference-links-images" ],
12
9
  "description":
13
10
  "Reference links and images should use a label that is defined",
@@ -1,15 +1,12 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addError, ellipsify } = require("../helpers");
6
- const { getReferenceLinkImageData } = require("./cache");
3
+ import { addError, ellipsify } from "../helpers/helpers.cjs";
4
+ import { getReferenceLinkImageData } from "./cache.mjs";
7
5
 
8
6
  const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
9
7
 
10
- // eslint-disable-next-line jsdoc/valid-types
11
- /** @type import("./markdownlint").Rule */
12
- module.exports = {
8
+ /** @type {import("markdownlint").Rule} */
9
+ export default {
13
10
  "names": [ "MD053", "link-image-reference-definitions" ],
14
11
  "description": "Link and image reference definitions should be needed",
15
12
  "tags": [ "images", "links" ],
@@ -1,10 +1,8 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorContext, nextLinesRe } = require("../helpers");
6
- const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
7
- const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
3
+ import { addErrorContext, nextLinesRe } from "../helpers/helpers.cjs";
4
+ import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
+ import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
8
6
 
9
7
  const backslashEscapeRe = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
10
8
  const removeBackslashEscapes = (text) => text.replace(backslashEscapeRe, "$1");
@@ -20,9 +18,8 @@ const autolinkAble = (destination) => {
20
18
  return !autolinkDisallowedRe.test(destination);
21
19
  };
22
20
 
23
- // eslint-disable-next-line jsdoc/valid-types
24
- /** @type import("./markdownlint").Rule */
25
- module.exports = {
21
+ /** @type {import("markdownlint").Rule} */
22
+ export default {
26
23
  "names": [ "MD054", "link-image-style" ],
27
24
  "description": "Link and image style",
28
25
  "tags": [ "images", "links" ],
@@ -1,9 +1,7 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorDetailIf } = require("../helpers");
6
- const { filterByTypesCached } = require("./cache");
3
+ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
+ import { filterByTypesCached } from "./cache.mjs";
7
5
 
8
6
  const whitespaceTypes = new Set([ "linePrefix", "whitespace" ]);
9
7
  const ignoreWhitespace = (tokens) => tokens.filter(
@@ -13,9 +11,10 @@ const firstOrNothing = (items) => items[0];
13
11
  const lastOrNothing = (items) => items[items.length - 1];
14
12
  const makeRange = (start, end) => [ start, end - start + 1 ];
15
13
 
16
- // eslint-disable-next-line jsdoc/valid-types
17
- /** @type import("./markdownlint").Rule */
18
- module.exports = {
14
+ /** @typedef {import("micromark-extension-gfm-table")} */
15
+
16
+ /** @type {import("markdownlint").Rule} */
17
+ export default {
19
18
  "names": [ "MD055", "table-pipe-style" ],
20
19
  "description": "Table pipe style",
21
20
  "tags": [ "table" ],
@@ -1,16 +1,15 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
4
-
5
- const { addErrorDetailIf } = require("../helpers");
6
- const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
7
- const { filterByTypesCached } = require("./cache");
3
+ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
+ import { getParentOfType } from "../helpers/micromark-helpers.cjs";
5
+ import { filterByTypesCached } from "./cache.mjs";
8
6
 
9
7
  const makeRange = (start, end) => [ start, end - start + 1 ];
10
8
 
11
- // eslint-disable-next-line jsdoc/valid-types
12
- /** @type import("./markdownlint").Rule */
13
- module.exports = {
9
+ /** @typedef {import("micromark-extension-gfm-table")} */
10
+
11
+ /** @type {import("markdownlint").Rule} */
12
+ export default {
14
13
  "names": [ "MD056", "table-column-count" ],
15
14
  "description": "Table column count",
16
15
  "tags": [ "table" ],
@@ -1,14 +1,13 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
3
+ import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
4
+ import { getBlockQuotePrefixText } from "../helpers/micromark-helpers.cjs";
5
+ import { filterByTypesCached } from "./cache.mjs";
4
6
 
5
- const { addErrorContext, isBlankLine } = require("../helpers");
6
- const { getBlockQuotePrefixText } = require("../helpers/micromark-helpers.cjs");
7
- const { filterByTypesCached } = require("./cache");
7
+ /** @typedef {import("micromark-extension-gfm-table")} */
8
8
 
9
- // eslint-disable-next-line jsdoc/valid-types
10
- /** @type import("./markdownlint").Rule */
11
- module.exports = {
9
+ /** @type {import("markdownlint").Rule} */
10
+ export default {
12
11
  "names": [ "MD058", "blanks-around-tables" ],
13
12
  "description": "Tables should be surrounded by blank lines",
14
13
  "tags": [ "table" ],
@@ -1,18 +1,24 @@
1
1
  // @ts-check
2
2
 
3
- "use strict";
3
+ import { directive } from "micromark-extension-directive";
4
+ import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
5
+ import { gfmFootnote } from "micromark-extension-gfm-footnote";
6
+ import { gfmTable } from "micromark-extension-gfm-table";
7
+ import { math } from "micromark-extension-math";
8
+ import { parse as micromarkParse, postprocess as micromarkPostprocess, preprocess as micromarkPreprocess } from "micromark";
9
+ // micromark-core-commonmark is not a dependency because this instance must match what's used by micromark
10
+ // eslint-disable-next-line n/no-extraneous-import
11
+ import { labelEnd } from "micromark-core-commonmark";
12
+ import { isHtmlFlowComment } from "../helpers/micromark-helpers.cjs";
13
+ import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "../helpers/shared.cjs";
4
14
 
5
- const micromark = require("markdownlint-micromark");
6
- const { isHtmlFlowComment } = require("./micromark-helpers.cjs");
7
- const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");
8
-
9
- /** @typedef {import("markdownlint-micromark").Construct} Construct */
10
- /** @typedef {import("markdownlint-micromark").Event} Event */
11
- /** @typedef {import("markdownlint-micromark").ParseOptions} MicromarkParseOptions */
12
- /** @typedef {import("markdownlint-micromark").State} State */
13
- /** @typedef {import("markdownlint-micromark").Token} Token */
14
- /** @typedef {import("markdownlint-micromark").Tokenizer} Tokenizer */
15
- /** @typedef {import("../lib/markdownlint.js").MicromarkToken} MicromarkToken */
15
+ /** @typedef {import("micromark-util-types").Event} Event */
16
+ /** @typedef {import("micromark-util-types").ParseOptions} MicromarkParseOptions */
17
+ /** @typedef {import("micromark-util-types").State} State */
18
+ /** @typedef {import("micromark-util-types").Token} Token */
19
+ /** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
20
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
21
+ /** @typedef {import("./micromark-types.d.mts")} */
16
22
 
17
23
  /**
18
24
  * Parse options.
@@ -28,27 +34,23 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");
28
34
  * @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark.
29
35
  * @returns {Event[]} Micromark events.
30
36
  */
31
- function getEvents(
37
+ export function getEvents(
32
38
  markdown,
33
39
  micromarkParseOptions = {}
34
40
  ) {
35
41
  // Customize extensions list to add useful extensions
36
42
  const extensions = [
37
- micromark.directive(),
38
- micromark.gfmAutolinkLiteral(),
39
- micromark.gfmFootnote(),
40
- micromark.gfmTable(),
41
- micromark.math(),
43
+ directive(),
44
+ gfmAutolinkLiteral(),
45
+ gfmFootnote(),
46
+ gfmTable(),
47
+ math(),
42
48
  ...(micromarkParseOptions.extensions || [])
43
49
  ];
44
50
 
45
51
  // // Shim labelEnd to identify undefined link labels
46
52
  /** @type {Event[][]} */
47
53
  const artificialEventLists = [];
48
- /** @type {Construct} */
49
- const labelEnd =
50
- // @ts-ignore
51
- micromark.labelEnd;
52
54
  const tokenizeOriginal = labelEnd.tokenize;
53
55
 
54
56
  /** @type {Tokenizer} */
@@ -162,9 +164,9 @@ function getEvents(
162
164
  // Use micromark to parse document into Events
163
165
  const encoding = undefined;
164
166
  const eol = true;
165
- const parseContext = micromark.parse({ ...micromarkParseOptions, extensions });
166
- const chunks = micromark.preprocess()(markdown, encoding, eol);
167
- const events = micromark.postprocess(parseContext.document().write(chunks));
167
+ const parseContext = micromarkParse({ ...micromarkParseOptions, extensions });
168
+ const chunks = micromarkPreprocess()(markdown, encoding, eol);
169
+ const events = micromarkPostprocess(parseContext.document().write(chunks));
168
170
 
169
171
  // Append artificial events and return all events
170
172
  // eslint-disable-next-line unicorn/prefer-spread
@@ -214,8 +216,7 @@ function parseInternal(
214
216
  };
215
217
  const history = [ root ];
216
218
  let current = root;
217
- // eslint-disable-next-line jsdoc/valid-types
218
- /** @type MicromarkParseOptions | null */
219
+ /** @type {MicromarkParseOptions | null} */
219
220
  let reparseOptions = null;
220
221
  let lines = null;
221
222
  let skipHtmlFlowChildren = false;
@@ -303,11 +304,6 @@ function parseInternal(
303
304
  * @param {ParseOptions} [parseOptions] Options.
304
305
  * @returns {MicromarkToken[]} Micromark tokens.
305
306
  */
306
- function parse(markdown, parseOptions) {
307
+ export function parse(markdown, parseOptions) {
307
308
  return parseInternal(markdown, parseOptions);
308
309
  }
309
-
310
- module.exports = {
311
- getEvents,
312
- parse
313
- };
@@ -0,0 +1,11 @@
1
+ export {};
2
+
3
+ // Augment TokenTypeMap with markdownlint-specific types.
4
+ declare module "micromark-util-types" {
5
+ export interface TokenTypeMap {
6
+ undefinedReference: "undefinedReference"
7
+ undefinedReferenceCollapsed: "undefinedReferenceCollapsed"
8
+ undefinedReferenceFull: "undefinedReferenceFull"
9
+ undefinedReferenceShortcut: "undefinedReferenceShortcut"
10
+ }
11
+ }
package/lib/rules.mjs ADDED
@@ -0,0 +1,118 @@
1
+ // @ts-check
2
+
3
+ import { homepage, version } from "./constants.mjs";
4
+
5
+ import md001 from "./md001.mjs";
6
+ import md003 from "./md003.mjs";
7
+ import md004 from "./md004.mjs";
8
+ import md005 from "./md005.mjs";
9
+ import md007 from "./md007.mjs";
10
+ import md009 from "./md009.mjs";
11
+ import md010 from "./md010.mjs";
12
+ import md011 from "./md011.mjs";
13
+ import md012 from "./md012.mjs";
14
+ import md013 from "./md013.mjs";
15
+ import md014 from "./md014.mjs";
16
+ import md018 from "./md018.mjs";
17
+ import md019md021 from "./md019-md021.mjs";
18
+ const [ md019, md021 ] = md019md021;
19
+ import md020 from "./md020.mjs";
20
+ import md022 from "./md022.mjs";
21
+ import md023 from "./md023.mjs";
22
+ import md024 from "./md024.mjs";
23
+ import md025 from "./md025.mjs";
24
+ import md026 from "./md026.mjs";
25
+ import md027 from "./md027.mjs";
26
+ import md028 from "./md028.mjs";
27
+ import md029 from "./md029.mjs";
28
+ import md030 from "./md030.mjs";
29
+ import md031 from "./md031.mjs";
30
+ import md032 from "./md032.mjs";
31
+ import md033 from "./md033.mjs";
32
+ import md034 from "./md034.mjs";
33
+ import md035 from "./md035.mjs";
34
+ import md036 from "./md036.mjs";
35
+ import md037 from "./md037.mjs";
36
+ import md038 from "./md038.mjs";
37
+ import md039 from "./md039.mjs";
38
+ import md040 from "./md040.mjs";
39
+ import md041 from "./md041.mjs";
40
+ import md042 from "./md042.mjs";
41
+ import md043 from "./md043.mjs";
42
+ import md044 from "./md044.mjs";
43
+ import md045 from "./md045.mjs";
44
+ import md046 from "./md046.mjs";
45
+ import md047 from "./md047.mjs";
46
+ import md048 from "./md048.mjs";
47
+ import md049md050 from "./md049-md050.mjs";
48
+ const [ md049, md050 ] = md049md050;
49
+ import md051 from "./md051.mjs";
50
+ import md052 from "./md052.mjs";
51
+ import md053 from "./md053.mjs";
52
+ import md054 from "./md054.mjs";
53
+ import md055 from "./md055.mjs";
54
+ import md056 from "./md056.mjs";
55
+ import md058 from "./md058.mjs";
56
+
57
+ const rules = [
58
+ md001,
59
+ // md002: Deprecated and removed
60
+ md003,
61
+ md004,
62
+ md005,
63
+ // md006: Deprecated and removed
64
+ md007,
65
+ md009,
66
+ md010,
67
+ md011,
68
+ md012,
69
+ md013,
70
+ md014,
71
+ md018,
72
+ md019,
73
+ md020,
74
+ md021,
75
+ md022,
76
+ md023,
77
+ md024,
78
+ md025,
79
+ md026,
80
+ md027,
81
+ md028,
82
+ md029,
83
+ md030,
84
+ md031,
85
+ md032,
86
+ md033,
87
+ md034,
88
+ md035,
89
+ md036,
90
+ md037,
91
+ md038,
92
+ md039,
93
+ md040,
94
+ md041,
95
+ md042,
96
+ md043,
97
+ md044,
98
+ md045,
99
+ md046,
100
+ md047,
101
+ md048,
102
+ md049,
103
+ md050,
104
+ md051,
105
+ md052,
106
+ md053,
107
+ md054,
108
+ md055,
109
+ md056,
110
+ // md057: See https://github.com/markdownlint/markdownlint
111
+ md058
112
+ ];
113
+ for (const rule of rules) {
114
+ const name = rule.names[0].toLowerCase();
115
+ // eslint-disable-next-line dot-notation
116
+ rule["information"] = new URL(`${homepage}/blob/v${version}/doc/${name}.md`);
117
+ }
118
+ export default rules;
@@ -0,0 +1,12 @@
1
+ declare module "markdownlint" {
2
+ export * from "./exports.mjs";
3
+ }
4
+ declare module "markdownlint/async" {
5
+ export * from "./exports-async.mjs";
6
+ }
7
+ declare module "markdownlint/promise" {
8
+ export * from "./exports-promise.mjs";
9
+ }
10
+ declare module "markdownlint/sync" {
11
+ export * from "./exports-sync.mjs";
12
+ }