markdownlint 0.34.0 → 0.36.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 (90) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +97 -45
  3. package/demo/markdownlint-browser.js +2186 -2164
  4. package/doc/CustomRules.md +66 -255
  5. package/doc/Rules.md +102 -29
  6. package/doc/md003.md +2 -2
  7. package/doc/md004.md +4 -3
  8. package/doc/md034.md +5 -0
  9. package/doc/md035.md +3 -8
  10. package/doc/md044.md +10 -0
  11. package/doc/md046.md +2 -2
  12. package/doc/md048.md +3 -2
  13. package/doc/md049.md +4 -3
  14. package/doc/md050.md +4 -4
  15. package/doc/md051.md +11 -3
  16. package/doc/md055.md +3 -2
  17. package/doc/md058.md +48 -0
  18. package/helpers/README.md +2 -45
  19. package/helpers/helpers.js +115 -607
  20. package/helpers/micromark-helpers.cjs +296 -0
  21. package/helpers/micromark-parse.cjs +313 -0
  22. package/helpers/package.json +5 -2
  23. package/helpers/shared.js +6 -0
  24. package/helpers/test.cjs +28 -0
  25. package/lib/cache.js +62 -13
  26. package/lib/configuration-strict.d.ts +1199 -0
  27. package/lib/configuration.d.ts +3 -1173
  28. package/lib/constants.js +3 -2
  29. package/lib/markdownit.cjs +172 -0
  30. package/lib/markdownlint.d.ts +103 -56
  31. package/lib/markdownlint.js +180 -120
  32. package/lib/md001.js +15 -9
  33. package/lib/md003.js +14 -9
  34. package/lib/md004.js +55 -48
  35. package/lib/md005.js +4 -13
  36. package/lib/md007.js +7 -11
  37. package/lib/md009.js +50 -44
  38. package/lib/md010.js +52 -33
  39. package/lib/md011.js +32 -23
  40. package/lib/md012.js +17 -9
  41. package/lib/md013.js +44 -38
  42. package/lib/md014.js +31 -38
  43. package/lib/md018.js +17 -9
  44. package/lib/md019-md021.js +80 -0
  45. package/lib/md020.js +14 -8
  46. package/lib/md022.js +13 -29
  47. package/lib/md023.js +22 -23
  48. package/lib/md024.js +12 -9
  49. package/lib/md025.js +15 -10
  50. package/lib/md026.js +2 -7
  51. package/lib/md027.js +7 -12
  52. package/lib/md028.js +3 -8
  53. package/lib/md029.js +40 -34
  54. package/lib/md030.js +4 -10
  55. package/lib/md031.js +45 -23
  56. package/lib/md032.js +33 -31
  57. package/lib/md033.js +3 -8
  58. package/lib/md034.js +21 -34
  59. package/lib/md035.js +2 -7
  60. package/lib/md036.js +19 -24
  61. package/lib/md037.js +3 -8
  62. package/lib/md038.js +11 -22
  63. package/lib/md039.js +64 -54
  64. package/lib/md040.js +13 -20
  65. package/lib/md041.js +5 -5
  66. package/lib/md042.js +44 -38
  67. package/lib/md043.js +20 -14
  68. package/lib/md044.js +34 -36
  69. package/lib/md045.js +5 -10
  70. package/lib/md046.js +2 -8
  71. package/lib/md048.js +30 -23
  72. package/lib/md049-md050.js +22 -12
  73. package/lib/md051.js +20 -28
  74. package/lib/md052.js +2 -2
  75. package/lib/md053.js +7 -6
  76. package/lib/md054.js +16 -23
  77. package/lib/md055.js +41 -49
  78. package/lib/md056.js +32 -33
  79. package/lib/md058.js +58 -0
  80. package/lib/rules.js +11 -4
  81. package/package.json +23 -20
  82. package/schema/.markdownlint.jsonc +58 -52
  83. package/schema/.markdownlint.yaml +56 -51
  84. package/schema/ValidatingConfiguration.md +6 -8
  85. package/schema/markdownlint-config-schema-strict.json +1841 -0
  86. package/schema/markdownlint-config-schema.json +141 -109
  87. package/style/prettier.json +1 -0
  88. package/helpers/micromark.cjs +0 -445
  89. package/lib/md019.js +0 -42
  90. package/lib/md021.js +0 -65
package/lib/constants.js CHANGED
@@ -8,7 +8,8 @@ module.exports.fixableRuleNames = [
8
8
  "MD012", "MD014", "MD018", "MD019", "MD020", "MD021",
9
9
  "MD022", "MD023", "MD026", "MD027", "MD030", "MD031",
10
10
  "MD032", "MD034", "MD037", "MD038", "MD039", "MD044",
11
- "MD047", "MD049", "MD050", "MD051", "MD053", "MD054"
11
+ "MD047", "MD049", "MD050", "MD051", "MD053", "MD054",
12
+ "MD058"
12
13
  ];
13
14
  module.exports.homepage = "https://github.com/DavidAnson/markdownlint";
14
- module.exports.version = "0.34.0";
15
+ module.exports.version = "0.36.0";
@@ -0,0 +1,172 @@
1
+ // @ts-check
2
+
3
+ "use strict";
4
+
5
+ const { newLineRe } = require("../helpers");
6
+
7
+ /**
8
+ * @callback InlineCodeSpanCallback
9
+ * @param {string} code Code content.
10
+ * @param {number} lineIndex Line index (0-based).
11
+ * @param {number} columnIndex Column index (0-based).
12
+ * @param {number} ticks Count of backticks.
13
+ * @returns {void}
14
+ */
15
+
16
+ /**
17
+ * Calls the provided function for each inline code span's content.
18
+ *
19
+ * @param {string} input Markdown content.
20
+ * @param {InlineCodeSpanCallback} handler Callback function taking (code,
21
+ * lineIndex, columnIndex, ticks).
22
+ * @returns {void}
23
+ */
24
+ function forEachInlineCodeSpan(input, handler) {
25
+ const backtickRe = /`+/g;
26
+ let match = null;
27
+ const backticksLengthAndIndex = [];
28
+ while ((match = backtickRe.exec(input)) !== null) {
29
+ backticksLengthAndIndex.push([ match[0].length, match.index ]);
30
+ }
31
+ const newLinesIndex = [];
32
+ while ((match = newLineRe.exec(input)) !== null) {
33
+ newLinesIndex.push(match.index);
34
+ }
35
+ let lineIndex = 0;
36
+ let lineStartIndex = 0;
37
+ let k = 0;
38
+ for (let i = 0; i < backticksLengthAndIndex.length - 1; i++) {
39
+ const [ startLength, startIndex ] = backticksLengthAndIndex[i];
40
+ if ((startIndex === 0) || (input[startIndex - 1] !== "\\")) {
41
+ for (let j = i + 1; j < backticksLengthAndIndex.length; j++) {
42
+ const [ endLength, endIndex ] = backticksLengthAndIndex[j];
43
+ if (startLength === endLength) {
44
+ for (; k < newLinesIndex.length; k++) {
45
+ const newLineIndex = newLinesIndex[k];
46
+ if (startIndex < newLineIndex) {
47
+ break;
48
+ }
49
+ lineIndex++;
50
+ lineStartIndex = newLineIndex + 1;
51
+ }
52
+ const columnIndex = startIndex - lineStartIndex + startLength;
53
+ handler(
54
+ input.slice(startIndex + startLength, endIndex),
55
+ lineIndex,
56
+ columnIndex,
57
+ startLength
58
+ );
59
+ i = j;
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Freeze all freeze-able members of a token and its children.
69
+ *
70
+ * @param {import("./markdownlint").MarkdownItToken} token A markdown-it token.
71
+ * @returns {void}
72
+ */
73
+ function freezeToken(token) {
74
+ if (token.attrs) {
75
+ for (const attr of token.attrs) {
76
+ Object.freeze(attr);
77
+ }
78
+ Object.freeze(token.attrs);
79
+ }
80
+ if (token.children) {
81
+ for (const child of token.children) {
82
+ freezeToken(child);
83
+ }
84
+ Object.freeze(token.children);
85
+ }
86
+ if (token.map) {
87
+ Object.freeze(token.map);
88
+ }
89
+ Object.freeze(token);
90
+ }
91
+
92
+ /**
93
+ * Annotate tokens with line/lineNumber and freeze them.
94
+ *
95
+ * @param {Object[]} tokens Array of markdown-it tokens.
96
+ * @param {string[]} lines Lines of Markdown content.
97
+ * @returns {void}
98
+ */
99
+ function annotateAndFreezeTokens(tokens, lines) {
100
+ let trMap = null;
101
+ // eslint-disable-next-line jsdoc/valid-types
102
+ /** @type import("./markdownlint").MarkdownItToken[] */
103
+ // @ts-ignore
104
+ const markdownItTokens = tokens;
105
+ for (const token of markdownItTokens) {
106
+ // Provide missing maps for table content
107
+ if (token.type === "tr_open") {
108
+ trMap = token.map;
109
+ } else if (token.type === "tr_close") {
110
+ trMap = null;
111
+ }
112
+ if (!token.map && trMap) {
113
+ token.map = [ ...trMap ];
114
+ }
115
+ // Update token metadata
116
+ if (token.map) {
117
+ token.line = lines[token.map[0]];
118
+ token.lineNumber = token.map[0] + 1;
119
+ // Trim bottom of token to exclude whitespace lines
120
+ while (token.map[1] && !((lines[token.map[1] - 1] || "").trim())) {
121
+ token.map[1]--;
122
+ }
123
+ }
124
+ // Annotate children with lineNumber
125
+ if (token.children) {
126
+ const codeSpanExtraLines = [];
127
+ if (token.children.some((child) => child.type === "code_inline")) {
128
+ forEachInlineCodeSpan(token.content, (code) => {
129
+ codeSpanExtraLines.push(code.split(newLineRe).length - 1);
130
+ });
131
+ }
132
+ let lineNumber = token.lineNumber;
133
+ for (const child of token.children) {
134
+ child.lineNumber = lineNumber;
135
+ child.line = lines[lineNumber - 1];
136
+ if ((child.type === "softbreak") || (child.type === "hardbreak")) {
137
+ lineNumber++;
138
+ } else if (child.type === "code_inline") {
139
+ lineNumber += codeSpanExtraLines.shift();
140
+ }
141
+ }
142
+ }
143
+ freezeToken(token);
144
+ }
145
+ Object.freeze(tokens);
146
+ }
147
+
148
+ /**
149
+ * Gets an array of markdown-it tokens for the input.
150
+ *
151
+ * @param {import("./markdownlint").Plugin[]} markdownItPlugins Additional plugins.
152
+ * @param {string} content Markdown content.
153
+ * @param {string[]} lines Lines of Markdown content.
154
+ * @returns {import("../lib/markdownlint").MarkdownItToken} Array of markdown-it tokens.
155
+ */
156
+ function getMarkdownItTokens(markdownItPlugins, content, lines) {
157
+ const markdownit = require("markdown-it");
158
+ const md = markdownit({ "html": true });
159
+ for (const plugin of markdownItPlugins) {
160
+ // @ts-ignore
161
+ md.use(...plugin);
162
+ }
163
+ const tokens = md.parse(content, {});
164
+ annotateAndFreezeTokens(tokens, lines);
165
+ // @ts-ignore
166
+ return tokens;
167
+ };
168
+
169
+ module.exports = {
170
+ forEachInlineCodeSpan,
171
+ getMarkdownItTokens
172
+ };
@@ -8,63 +8,8 @@ export = markdownlint;
8
8
  */
9
9
  declare function markdownlint(options: Options | null, callback: LintCallback): void;
10
10
  declare namespace markdownlint {
11
- export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, RuleFunction, RuleParams, MarkdownParsers, ParserMarkdownIt, ParserMicromark, MarkdownItToken, MicromarkTokenType, MicromarkToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
11
+ export { markdownlintSync as sync, readConfig, readConfigSync, getVersion, promises, applyFix, applyFixes, RuleFunction, RuleParams, MarkdownParsers, ParserMarkdownIt, ParserMicromark, MarkdownItToken, MicromarkTokenType, MicromarkToken, RuleOnError, RuleOnErrorInfo, RuleOnErrorFixInfo, RuleOnErrorFixInfoNormalized, Rule, Options, Plugin, ToStringCallback, LintResults, LintError, FixInfo, LintContentCallback, LintCallback, Configuration, ConfigurationStrict, RuleConfiguration, ConfigurationParser, ReadConfigCallback, ResolveConfigExtendsCallback };
12
12
  }
13
- /**
14
- * Configuration options.
15
- */
16
- type Options = {
17
- /**
18
- * Configuration object.
19
- */
20
- config?: Configuration;
21
- /**
22
- * Configuration parsers.
23
- */
24
- configParsers?: ConfigurationParser[];
25
- /**
26
- * Custom rules.
27
- */
28
- customRules?: Rule[] | Rule;
29
- /**
30
- * Files to lint.
31
- */
32
- files?: string[] | string;
33
- /**
34
- * Front matter pattern.
35
- */
36
- frontMatter?: RegExp | null;
37
- /**
38
- * File system implementation.
39
- */
40
- fs?: any;
41
- /**
42
- * True to catch exceptions.
43
- */
44
- handleRuleFailures?: boolean;
45
- /**
46
- * Additional plugins.
47
- */
48
- markdownItPlugins?: Plugin[];
49
- /**
50
- * True to ignore HTML directives.
51
- */
52
- noInlineConfig?: boolean;
53
- /**
54
- * Results object version.
55
- */
56
- resultVersion?: number;
57
- /**
58
- * Strings to lint.
59
- */
60
- strings?: {
61
- [x: string]: string;
62
- };
63
- };
64
- /**
65
- * Called with the result of the lint function.
66
- */
67
- type LintCallback = (error: Error | null, results?: LintResults) => void;
68
13
  /**
69
14
  * Lint specified Markdown files synchronously.
70
15
  *
@@ -104,6 +49,23 @@ declare namespace promises {
104
49
  export { extendConfigPromise as extendConfig };
105
50
  export { readConfigPromise as readConfig };
106
51
  }
52
+ /**
53
+ * Applies the specified fix to a Markdown content line.
54
+ *
55
+ * @param {string} line Line of Markdown content.
56
+ * @param {RuleOnErrorFixInfo} fixInfo RuleOnErrorFixInfo instance.
57
+ * @param {string} [lineEnding] Line ending to use.
58
+ * @returns {string | null} Fixed content or null if deleted.
59
+ */
60
+ declare function applyFix(line: string, fixInfo: RuleOnErrorFixInfo, lineEnding?: string): string | null;
61
+ /**
62
+ * Applies as many of the specified fixes as possible to Markdown content.
63
+ *
64
+ * @param {string} input Lines of Markdown content.
65
+ * @param {RuleOnErrorInfo[]} errors RuleOnErrorInfo instances.
66
+ * @returns {string} Fixed content.
67
+ */
68
+ declare function applyFixes(input: string, errors: RuleOnErrorInfo[]): string;
107
69
  /**
108
70
  * Function to implement rule logic.
109
71
  */
@@ -132,6 +94,10 @@ type RuleParams = {
132
94
  * Rule configuration.
133
95
  */
134
96
  config: RuleConfiguration;
97
+ /**
98
+ * Version of the markdownlint library.
99
+ */
100
+ version: string;
135
101
  };
136
102
  /**
137
103
  * Markdown parser data.
@@ -321,6 +287,27 @@ type RuleOnErrorFixInfo = {
321
287
  */
322
288
  insertText?: string;
323
289
  };
290
+ /**
291
+ * RuleOnErrorInfo with all optional properties present.
292
+ */
293
+ type RuleOnErrorFixInfoNormalized = {
294
+ /**
295
+ * Line number (1-based).
296
+ */
297
+ lineNumber: number;
298
+ /**
299
+ * Column of the fix (1-based).
300
+ */
301
+ editColumn: number;
302
+ /**
303
+ * Count of characters to delete.
304
+ */
305
+ deleteCount: number;
306
+ /**
307
+ * Text to insert (after deleting).
308
+ */
309
+ insertText: string;
310
+ };
324
311
  /**
325
312
  * Rule definition.
326
313
  */
@@ -354,6 +341,57 @@ type Rule = {
354
341
  */
355
342
  function: RuleFunction;
356
343
  };
344
+ /**
345
+ * Configuration options.
346
+ */
347
+ type Options = {
348
+ /**
349
+ * Configuration object.
350
+ */
351
+ config?: Configuration;
352
+ /**
353
+ * Configuration parsers.
354
+ */
355
+ configParsers?: ConfigurationParser[];
356
+ /**
357
+ * Custom rules.
358
+ */
359
+ customRules?: Rule[] | Rule;
360
+ /**
361
+ * Files to lint.
362
+ */
363
+ files?: string[] | string;
364
+ /**
365
+ * Front matter pattern.
366
+ */
367
+ frontMatter?: RegExp | null;
368
+ /**
369
+ * File system implementation.
370
+ */
371
+ fs?: any;
372
+ /**
373
+ * True to catch exceptions.
374
+ */
375
+ handleRuleFailures?: boolean;
376
+ /**
377
+ * Additional plugins.
378
+ */
379
+ markdownItPlugins?: Plugin[];
380
+ /**
381
+ * True to ignore HTML directives.
382
+ */
383
+ noInlineConfig?: boolean;
384
+ /**
385
+ * Results object version.
386
+ */
387
+ resultVersion?: number;
388
+ /**
389
+ * Strings to lint.
390
+ */
391
+ strings?: {
392
+ [x: string]: string;
393
+ };
394
+ };
357
395
  /**
358
396
  * A markdown-it plugin.
359
397
  */
@@ -430,11 +468,20 @@ type FixInfo = {
430
468
  * Called with the result of linting a string or document.
431
469
  */
432
470
  type LintContentCallback = (error: Error | null, result?: LintError[]) => void;
471
+ /**
472
+ * Called with the result of the lint function.
473
+ */
474
+ type LintCallback = (error: Error | null, results?: LintResults) => void;
433
475
  /**
434
476
  * Configuration object for linting rules. For the JSON schema, see
435
477
  * {@link ../schema/markdownlint-config-schema.json}.
436
478
  */
437
479
  type Configuration = import("./configuration").Configuration;
480
+ /**
481
+ * Configuration object for linting rules strictly. For the JSON schema, see
482
+ * {@link ../schema/markdownlint-config-schema-strict.json}.
483
+ */
484
+ type ConfigurationStrict = import("./configuration-strict").ConfigurationStrict;
438
485
  /**
439
486
  * Rule configuration.
440
487
  */