markdownlint 0.37.3 → 0.38.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 (50) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +2 -3
  3. package/README.md +39 -21
  4. package/doc/Rules.md +158 -35
  5. package/doc/md027.md +8 -0
  6. package/doc/md038.md +23 -11
  7. package/doc/md041.md +31 -16
  8. package/doc/md043.md +22 -4
  9. package/doc/md045.md +9 -1
  10. package/doc/md051.md +17 -0
  11. package/doc/md052.md +12 -0
  12. package/doc/md053.md +3 -3
  13. package/doc/md059.md +30 -0
  14. package/helpers/README.md +2 -2
  15. package/helpers/helpers.cjs +4 -6
  16. package/helpers/micromark-helpers.cjs +29 -3
  17. package/helpers/package.json +1 -1
  18. package/lib/cache.mjs +19 -5
  19. package/lib/configuration-strict.d.ts +190 -126
  20. package/lib/constants.mjs +1 -1
  21. package/lib/defer-require.cjs +16 -0
  22. package/lib/exports.d.mts +2 -0
  23. package/lib/exports.mjs +2 -0
  24. package/lib/markdownit.cjs +6 -13
  25. package/lib/markdownlint.d.mts +36 -2
  26. package/lib/markdownlint.mjs +314 -292
  27. package/lib/md025.mjs +23 -15
  28. package/lib/md027.mjs +11 -1
  29. package/lib/md036.mjs +12 -2
  30. package/lib/md038.mjs +52 -71
  31. package/lib/md039.mjs +3 -22
  32. package/lib/md041.mjs +54 -16
  33. package/lib/md043.mjs +2 -0
  34. package/lib/md045.mjs +3 -1
  35. package/lib/md051.mjs +13 -5
  36. package/lib/md052.mjs +2 -1
  37. package/lib/md059.mjs +71 -0
  38. package/lib/micromark-parse.mjs +14 -3
  39. package/lib/node-imports-browser.mjs +0 -2
  40. package/lib/node-imports-node.mjs +0 -3
  41. package/lib/parse-configuration.mjs +46 -0
  42. package/lib/resolve-module.cjs +52 -0
  43. package/lib/resolve-module.d.cts +34 -0
  44. package/lib/rules.mjs +3 -1
  45. package/package.json +30 -27
  46. package/schema/.markdownlint.jsonc +82 -60
  47. package/schema/.markdownlint.yaml +74 -56
  48. package/schema/markdownlint-config-schema-strict.json +259 -144
  49. package/schema/markdownlint-config-schema.json +259 -144
  50. package/lib/node-imports-browser-module.cjs +0 -7
package/lib/constants.mjs CHANGED
@@ -10,4 +10,4 @@ export const fixableRuleNames = [
10
10
  "MD058"
11
11
  ];
12
12
  export const homepage = "https://github.com/DavidAnson/markdownlint";
13
- export const version = "0.37.3";
13
+ export const version = "0.38.0";
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ /**
6
+ * Calls require for markdownit.cjs. Used to synchronously defer loading because module.createRequire is buggy under webpack (https://github.com/webpack/webpack/issues/16724).
7
+ *
8
+ * @returns {any} Exported module content.
9
+ */
10
+ function requireMarkdownItCjs() {
11
+ return require("./markdownit.cjs");
12
+ }
13
+
14
+ module.exports = {
15
+ requireMarkdownItCjs
16
+ };
package/lib/exports.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ export { resolveModule } from "./resolve-module.cjs";
1
2
  export type Configuration = import("./markdownlint.mjs").Configuration;
2
3
  export type ConfigurationParser = import("./markdownlint.mjs").ConfigurationParser;
3
4
  export type ConfigurationStrict = import("./markdownlint.mjs").ConfigurationStrict;
@@ -6,6 +7,7 @@ export type LintCallback = import("./markdownlint.mjs").LintCallback;
6
7
  export type LintContentCallback = import("./markdownlint.mjs").LintContentCallback;
7
8
  export type LintError = import("./markdownlint.mjs").LintError;
8
9
  export type LintResults = import("./markdownlint.mjs").LintResults;
10
+ export type MarkdownItFactory = import("./markdownlint.mjs").MarkdownItFactory;
9
11
  export type MarkdownItToken = import("./markdownlint.mjs").MarkdownItToken;
10
12
  export type MarkdownParsers = import("./markdownlint.mjs").MarkdownParsers;
11
13
  export type MicromarkToken = import("./markdownlint.mjs").MicromarkToken;
package/lib/exports.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  // @ts-check
2
2
 
3
3
  export { applyFix, applyFixes, getVersion } from "./markdownlint.mjs";
4
+ export { resolveModule } from "./resolve-module.cjs";
4
5
 
5
6
  /** @typedef {import("./markdownlint.mjs").Configuration} Configuration */
6
7
  /** @typedef {import("./markdownlint.mjs").ConfigurationParser} ConfigurationParser */
@@ -10,6 +11,7 @@ export { applyFix, applyFixes, getVersion } from "./markdownlint.mjs";
10
11
  /** @typedef {import("./markdownlint.mjs").LintContentCallback} LintContentCallback */
11
12
  /** @typedef {import("./markdownlint.mjs").LintError} LintError */
12
13
  /** @typedef {import("./markdownlint.mjs").LintResults} LintResults */
14
+ /** @typedef {import("./markdownlint.mjs").MarkdownItFactory} MarkdownItFactory */
13
15
  /** @typedef {import("./markdownlint.mjs").MarkdownItToken} MarkdownItToken */
14
16
  /** @typedef {import("./markdownlint.mjs").MarkdownParsers} MarkdownParsers */
15
17
  /** @typedef {import("./markdownlint.mjs").MicromarkToken} MicromarkToken */
@@ -5,8 +5,8 @@
5
5
  const { newLineRe } = require("../helpers");
6
6
 
7
7
  // @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
8
+ /** @typedef {import("markdownlint").MarkdownIt} MarkdownIt */
8
9
  /** @typedef {import("markdownlint").MarkdownItToken} MarkdownItToken */
9
- // @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
10
10
  /** @typedef {import("markdownlint").Plugin} Plugin */
11
11
 
12
12
  /**
@@ -97,7 +97,7 @@ function freezeToken(token) {
97
97
  /**
98
98
  * Annotate tokens with line/lineNumber and freeze them.
99
99
  *
100
- * @param {Object[]} tokens Array of markdown-it tokens.
100
+ * @param {import("markdown-it").Token[]} tokens Array of markdown-it tokens.
101
101
  * @param {string[]} lines Lines of Markdown content.
102
102
  * @returns {void}
103
103
  */
@@ -152,21 +152,14 @@ function annotateAndFreezeTokens(tokens, lines) {
152
152
  /**
153
153
  * Gets an array of markdown-it tokens for the input.
154
154
  *
155
- * @param {Plugin[]} markdownItPlugins Additional plugins.
155
+ * @param {MarkdownIt} markdownIt Instance of the markdown-it parser.
156
156
  * @param {string} content Markdown content.
157
157
  * @param {string[]} lines Lines of Markdown content.
158
- * @returns {MarkdownItToken} Array of markdown-it tokens.
158
+ * @returns {MarkdownItToken[]} Array of markdown-it tokens.
159
159
  */
160
- function getMarkdownItTokens(markdownItPlugins, content, lines) {
161
- const markdownit = require("markdown-it");
162
- const md = markdownit({ "html": true });
163
- for (const plugin of markdownItPlugins) {
164
- // @ts-ignore
165
- md.use(...plugin);
166
- }
167
- const tokens = md.parse(content, {});
160
+ function getMarkdownItTokens(markdownIt, content, lines) {
161
+ const tokens = markdownIt.parse(content, {});
168
162
  annotateAndFreezeTokens(tokens, lines);
169
- // @ts-ignore
170
163
  return tokens;
171
164
  };
172
165
 
@@ -82,6 +82,23 @@ export function applyFixes(input: string, errors: RuleOnErrorInfo[]): string;
82
82
  * @returns {string} SemVer string.
83
83
  */
84
84
  export function getVersion(): string;
85
+ /**
86
+ * Result object for getEnabledRulesPerLineNumber.
87
+ */
88
+ export type EnabledRulesPerLineNumberResult = {
89
+ /**
90
+ * Effective configuration.
91
+ */
92
+ effectiveConfig: Configuration;
93
+ /**
94
+ * Enabled rules per line number.
95
+ */
96
+ enabledRulesPerLineNumber: any[];
97
+ /**
98
+ * Enabled rule list.
99
+ */
100
+ enabledRuleList: Rule[];
101
+ };
85
102
  /**
86
103
  * Function to implement rule logic.
87
104
  */
@@ -357,6 +374,23 @@ export type Rule = {
357
374
  */
358
375
  function: RuleFunction;
359
376
  };
377
+ /**
378
+ * Method used by the markdown-it parser to parse input.
379
+ */
380
+ export type MarkdownItParse = (src: string, env: any) => any[];
381
+ /**
382
+ * Instance of the markdown-it parser.
383
+ */
384
+ export type MarkdownIt = {
385
+ /**
386
+ * Method to parse input.
387
+ */
388
+ parse: MarkdownItParse;
389
+ };
390
+ /**
391
+ * Gets an instance of the markdown-it parser. Any plugins should already have been loaded.
392
+ */
393
+ export type MarkdownItFactory = () => MarkdownIt | Promise<MarkdownIt>;
360
394
  /**
361
395
  * Configuration options.
362
396
  */
@@ -390,9 +424,9 @@ export type Options = {
390
424
  */
391
425
  handleRuleFailures?: boolean;
392
426
  /**
393
- * Additional plugins.
427
+ * Function to create a markdown-it parser.
394
428
  */
395
- markdownItPlugins?: Plugin[];
429
+ markdownItFactory?: MarkdownItFactory;
396
430
  /**
397
431
  * True to ignore HTML directives.
398
432
  */