markdownlint 0.40.0 → 0.41.1

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 +15 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +13 -25
  4. package/doc/CustomRules.md +1 -1
  5. package/doc/Rules.md +80 -26
  6. package/doc/md001.md +1 -1
  7. package/doc/md011.md +1 -1
  8. package/doc/md022.md +15 -0
  9. package/doc/md025.md +1 -1
  10. package/doc/md026.md +1 -1
  11. package/doc/md028.md +13 -9
  12. package/doc/md029.md +11 -1
  13. package/doc/md034.md +1 -1
  14. package/doc/md035.md +12 -5
  15. package/doc/md041.md +2 -2
  16. package/doc/md042.md +6 -0
  17. package/doc/md045.md +1 -1
  18. package/doc/md060.md +15 -3
  19. package/helpers/README.md +4 -4
  20. package/helpers/helpers.cjs +55 -49
  21. package/helpers/micromark-helpers.cjs +5 -5
  22. package/helpers/package.json +2 -2
  23. package/helpers/shared.cjs +2 -2
  24. package/lib/cache.mjs +1 -0
  25. package/lib/configuration-strict.d.ts +116 -108
  26. package/lib/constants.mjs +2 -2
  27. package/lib/exports.d.mts +1 -0
  28. package/lib/exports.mjs +1 -0
  29. package/lib/markdownit.cjs +8 -7
  30. package/lib/markdownlint.d.mts +56 -41
  31. package/lib/markdownlint.mjs +40 -105
  32. package/lib/md004.mjs +1 -0
  33. package/lib/md005.mjs +1 -1
  34. package/lib/md019-md021.mjs +1 -0
  35. package/lib/md022.mjs +15 -11
  36. package/lib/md024.mjs +1 -1
  37. package/lib/md029.mjs +37 -25
  38. package/lib/md032.mjs +5 -4
  39. package/lib/md036.mjs +1 -0
  40. package/lib/md037.mjs +1 -2
  41. package/lib/md051.mjs +3 -1
  42. package/lib/md060.mjs +47 -8
  43. package/lib/micromark-parse.mjs +21 -5
  44. package/lib/resolve-module.cjs +4 -3
  45. package/lib/resolve-module.d.cts +1 -1
  46. package/package.json +37 -38
  47. package/schema/.markdownlint.jsonc +55 -53
  48. package/schema/.markdownlint.yaml +77 -75
  49. package/schema/markdownlint-config-schema-strict.json +120 -110
  50. package/schema/markdownlint-config-schema.json +120 -110
package/lib/constants.mjs CHANGED
@@ -8,7 +8,7 @@ export const fixableRuleNames = [
8
8
  "MD022", "MD023", "MD026", "MD027", "MD029", "MD030",
9
9
  "MD031", "MD032", "MD034", "MD037", "MD038", "MD039",
10
10
  "MD044", "MD047", "MD049", "MD050", "MD051", "MD053",
11
- "MD054", "MD058"
11
+ "MD054", "MD058", "MD060"
12
12
  ];
13
13
  export const homepage = "https://github.com/DavidAnson/markdownlint";
14
- export const version = "0.40.0";
14
+ export const version = "0.41.1";
package/lib/exports.d.mts CHANGED
@@ -9,6 +9,7 @@ export type LintContentCallback = import("./markdownlint.mjs").LintContentCallba
9
9
  export type LintError = import("./markdownlint.mjs").LintError;
10
10
  export type LintResults = import("./markdownlint.mjs").LintResults;
11
11
  export type MarkdownItFactory = import("./markdownlint.mjs").MarkdownItFactory;
12
+ export type MarkdownItBaseToken = import("./markdownlint.mjs").MarkdownItBaseToken;
12
13
  export type MarkdownItToken = import("./markdownlint.mjs").MarkdownItToken;
13
14
  export type MarkdownParsers = import("./markdownlint.mjs").MarkdownParsers;
14
15
  export type MicromarkToken = import("./markdownlint.mjs").MicromarkToken;
package/lib/exports.mjs CHANGED
@@ -13,6 +13,7 @@ export { resolveModule } from "./resolve-module.cjs";
13
13
  /** @typedef {import("./markdownlint.mjs").LintError} LintError */
14
14
  /** @typedef {import("./markdownlint.mjs").LintResults} LintResults */
15
15
  /** @typedef {import("./markdownlint.mjs").MarkdownItFactory} MarkdownItFactory */
16
+ /** @typedef {import("./markdownlint.mjs").MarkdownItBaseToken} MarkdownItBaseToken */
16
17
  /** @typedef {import("./markdownlint.mjs").MarkdownItToken} MarkdownItToken */
17
18
  /** @typedef {import("./markdownlint.mjs").MarkdownParsers} MarkdownParsers */
18
19
  /** @typedef {import("./markdownlint.mjs").MicromarkToken} MicromarkToken */
@@ -2,10 +2,11 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const { newLineRe } = require("../helpers");
5
+ const { newlineRe } = require("../helpers/shared.cjs");
6
6
 
7
7
  // @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
8
8
  /** @typedef {import("markdownlint").MarkdownIt} MarkdownIt */
9
+ /** @typedef {import("markdownlint").MarkdownItBaseToken} MarkdownItBaseToken */
9
10
  /** @typedef {import("markdownlint").MarkdownItToken} MarkdownItToken */
10
11
  /** @typedef {import("markdownlint").Plugin} Plugin */
11
12
 
@@ -34,7 +35,7 @@ function forEachInlineCodeSpan(input, handler) {
34
35
  backticksLengthAndIndex.push([ match[0].length, match.index ]);
35
36
  }
36
37
  const newLinesIndex = [];
37
- while ((match = newLineRe.exec(input)) !== null) {
38
+ while ((match = newlineRe.exec(input)) !== null) {
38
39
  newLinesIndex.push(match.index);
39
40
  }
40
41
  let lineIndex = 0;
@@ -47,12 +48,12 @@ function forEachInlineCodeSpan(input, handler) {
47
48
  const [ endLength, endIndex ] = backticksLengthAndIndex[j];
48
49
  if (startLength === endLength) {
49
50
  for (; k < newLinesIndex.length; k++) {
50
- const newLineIndex = newLinesIndex[k];
51
- if (startIndex < newLineIndex) {
51
+ const newlineIndex = newLinesIndex[k];
52
+ if (startIndex < newlineIndex) {
52
53
  break;
53
54
  }
54
55
  lineIndex++;
55
- lineStartIndex = newLineIndex + 1;
56
+ lineStartIndex = newlineIndex + 1;
56
57
  }
57
58
  const columnIndex = startIndex - lineStartIndex + startLength;
58
59
  handler(
@@ -97,7 +98,7 @@ function freezeToken(token) {
97
98
  /**
98
99
  * Annotate tokens with line/lineNumber and freeze them.
99
100
  *
100
- * @param {import("markdown-it").Token[]} tokens Array of markdown-it tokens.
101
+ * @param {MarkdownItBaseToken[]} tokens Array of markdown-it tokens.
101
102
  * @param {string[]} lines Lines of Markdown content.
102
103
  * @returns {void}
103
104
  */
@@ -131,7 +132,7 @@ function annotateAndFreezeTokens(tokens, lines) {
131
132
  const codeSpanExtraLines = [];
132
133
  if (token.children.some((child) => child.type === "code_inline")) {
133
134
  forEachInlineCodeSpan(token.content, (code) => {
134
- codeSpanExtraLines.push(code.split(newLineRe).length - 1);
135
+ codeSpanExtraLines.push(code.split(newlineRe).length - 1);
135
136
  });
136
137
  }
137
138
  let lineNumber = token.lineNumber;
@@ -218,13 +218,13 @@ export type ParserMicromark = {
218
218
  tokens: MicromarkToken[];
219
219
  };
220
220
  /**
221
- * markdown-it token.
221
+ * markdown-it base token.
222
222
  */
223
- export type MarkdownItToken = {
223
+ export type MarkdownItBaseToken = {
224
224
  /**
225
225
  * HTML attributes.
226
226
  */
227
- attrs: string[][];
227
+ attrs: string[][] | null;
228
228
  /**
229
229
  * Block-level token.
230
230
  */
@@ -232,7 +232,7 @@ export type MarkdownItToken = {
232
232
  /**
233
233
  * Child nodes.
234
234
  */
235
- children: MarkdownItToken[];
235
+ children: MarkdownItBaseToken[] | null;
236
236
  /**
237
237
  * Tag contents.
238
238
  */
@@ -252,7 +252,7 @@ export type MarkdownItToken = {
252
252
  /**
253
253
  * Beginning/ending line numbers.
254
254
  */
255
- map: number[];
255
+ map: number[] | null;
256
256
  /**
257
257
  * Markup text.
258
258
  */
@@ -260,7 +260,7 @@ export type MarkdownItToken = {
260
260
  /**
261
261
  * Arbitrary data.
262
262
  */
263
- meta: any;
263
+ meta: Object;
264
264
  /**
265
265
  * Level change.
266
266
  */
@@ -273,6 +273,15 @@ export type MarkdownItToken = {
273
273
  * Token type.
274
274
  */
275
275
  type: string;
276
+ };
277
+ /**
278
+ * markdown-it extended token.
279
+ */
280
+ export type MarkdownItExtendedToken = {
281
+ /**
282
+ * Child nodes.
283
+ */
284
+ children: MarkdownItExtendedToken[] | null;
276
285
  /**
277
286
  * Line number (1-based).
278
287
  */
@@ -282,6 +291,10 @@ export type MarkdownItToken = {
282
291
  */
283
292
  line: string;
284
293
  };
294
+ /**
295
+ * markdown-it token.
296
+ */
297
+ export type MarkdownItToken = MarkdownItBaseToken & MarkdownItExtendedToken;
285
298
  export type MicromarkTokenType = import("micromark-util-types").TokenType;
286
299
  /**
287
300
  * micromark token.
@@ -335,23 +348,23 @@ export type RuleOnErrorInfo = {
335
348
  /**
336
349
  * Detail about the error.
337
350
  */
338
- detail?: string;
351
+ detail?: string | undefined;
339
352
  /**
340
353
  * Context for the error.
341
354
  */
342
- context?: string;
355
+ context?: string | undefined;
343
356
  /**
344
357
  * Link to more information.
345
358
  */
346
- information?: URL;
359
+ information?: URL | undefined;
347
360
  /**
348
361
  * Column number (1-based) and length.
349
362
  */
350
- range?: number[];
363
+ range?: number[] | undefined;
351
364
  /**
352
365
  * Fix information.
353
366
  */
354
- fixInfo?: RuleOnErrorFixInfo;
367
+ fixInfo?: RuleOnErrorFixInfo | undefined;
355
368
  };
356
369
  /**
357
370
  * Fix information for RuleOnErrorInfo.
@@ -360,19 +373,19 @@ export type RuleOnErrorFixInfo = {
360
373
  /**
361
374
  * Line number (1-based).
362
375
  */
363
- lineNumber?: number;
376
+ lineNumber?: number | undefined;
364
377
  /**
365
378
  * Column of the fix (1-based).
366
379
  */
367
- editColumn?: number;
380
+ editColumn?: number | undefined;
368
381
  /**
369
382
  * Count of characters to delete.
370
383
  */
371
- deleteCount?: number;
384
+ deleteCount?: number | undefined;
372
385
  /**
373
386
  * Text to insert (after deleting).
374
387
  */
375
- insertText?: string;
388
+ insertText?: string | undefined;
376
389
  };
377
390
  /**
378
391
  * Rule definition.
@@ -389,7 +402,7 @@ export type Rule = {
389
402
  /**
390
403
  * Link to more information.
391
404
  */
392
- information?: URL;
405
+ information?: URL | undefined;
393
406
  /**
394
407
  * Rule tag(s).
395
408
  */
@@ -401,7 +414,7 @@ export type Rule = {
401
414
  /**
402
415
  * True if asynchronous.
403
416
  */
404
- asynchronous?: boolean;
417
+ asynchronous?: boolean | undefined;
405
418
  /**
406
419
  * Rule implementation.
407
420
  */
@@ -410,7 +423,7 @@ export type Rule = {
410
423
  /**
411
424
  * Method used by the markdown-it parser to parse input.
412
425
  */
413
- export type MarkdownItParse = (src: string, env: any) => any[];
426
+ export type MarkdownItParse = (src: string, env: Object) => MarkdownItBaseToken[];
414
427
  /**
415
428
  * Instance of the markdown-it parser.
416
429
  */
@@ -431,50 +444,50 @@ export type Options = {
431
444
  /**
432
445
  * Configuration object.
433
446
  */
434
- config?: Configuration;
447
+ config?: import("./configuration.d.ts").Configuration | undefined;
435
448
  /**
436
449
  * Configuration parsers.
437
450
  */
438
- configParsers?: ConfigurationParser[];
451
+ configParsers?: ConfigurationParser[] | undefined;
439
452
  /**
440
453
  * Custom rules.
441
454
  */
442
- customRules?: Rule[] | Rule;
455
+ customRules?: Rule | Rule[] | undefined;
443
456
  /**
444
457
  * Files to lint.
445
458
  */
446
- files?: string[] | string;
459
+ files?: string | string[] | undefined;
447
460
  /**
448
461
  * Front matter pattern.
449
462
  */
450
- frontMatter?: RegExp | null;
463
+ frontMatter?: RegExp | null | undefined;
451
464
  /**
452
465
  * File system implementation.
453
466
  */
454
- fs?: FsLike;
467
+ fs?: FsLike | undefined;
455
468
  /**
456
469
  * True to catch exceptions.
457
470
  */
458
- handleRuleFailures?: boolean;
471
+ handleRuleFailures?: boolean | undefined;
459
472
  /**
460
473
  * Function to create a markdown-it parser.
461
474
  */
462
- markdownItFactory?: MarkdownItFactory;
475
+ markdownItFactory?: MarkdownItFactory | undefined;
463
476
  /**
464
477
  * True to ignore HTML directives.
465
478
  */
466
- noInlineConfig?: boolean;
479
+ noInlineConfig?: boolean | undefined;
467
480
  /**
468
481
  * Strings to lint.
469
482
  */
470
483
  strings?: {
471
484
  [x: string]: string;
472
- };
485
+ } | undefined;
473
486
  };
474
487
  /**
475
488
  * A markdown-it plugin.
476
489
  */
477
- export type Plugin = any[];
490
+ export type Plugin = Object[];
478
491
  /**
479
492
  * Lint results.
480
493
  */
@@ -529,19 +542,19 @@ export type FixInfo = {
529
542
  /**
530
543
  * Line number (1-based).
531
544
  */
532
- lineNumber?: number;
545
+ lineNumber?: number | undefined;
533
546
  /**
534
547
  * Column of the fix (1-based).
535
548
  */
536
- editColumn?: number;
549
+ editColumn?: number | undefined;
537
550
  /**
538
551
  * Count of characters to delete.
539
552
  */
540
- deleteCount?: number;
553
+ deleteCount?: number | undefined;
541
554
  /**
542
555
  * Text to insert (after deleting).
543
556
  */
544
- insertText?: string;
557
+ insertText?: string | undefined;
545
558
  };
546
559
  /**
547
560
  * FixInfo with all optional properties present.
@@ -567,11 +580,13 @@ export type FixInfoNormalized = {
567
580
  /**
568
581
  * Called with the result of linting a string or document.
569
582
  */
570
- export type LintContentCallback = (error: Error | null, result?: LintError[]) => void;
583
+ export type LintContentCallback = (error: Error | null, result?: LintError[] | undefined) => void;
571
584
  /**
572
585
  * Called with the result of the lint function.
573
586
  */
574
- export type LintCallback = (error: Error | null, results?: LintResults) => void;
587
+ export type LintCallback = (error: Error | null, results?: {
588
+ [x: string]: LintError[];
589
+ } | undefined) => void;
575
590
  /**
576
591
  * Configuration object for linting rules. For the JSON schema, see
577
592
  * {@link ../schema/markdownlint-config-schema.json}.
@@ -582,10 +597,6 @@ export type Configuration = import("./configuration.d.ts").Configuration;
582
597
  * {@link ../schema/markdownlint-config-schema-strict.json}.
583
598
  */
584
599
  export type ConfigurationStrict = import("./configuration-strict.d.ts").ConfigurationStrict;
585
- /**
586
- * Rule configuration.
587
- */
588
- export type RuleConfiguration = boolean | any;
589
600
  /**
590
601
  * Parses a configuration string and returns a configuration object.
591
602
  */
@@ -593,8 +604,12 @@ export type ConfigurationParser = (text: string) => Configuration;
593
604
  /**
594
605
  * Called with the result of the readConfig function.
595
606
  */
596
- export type ReadConfigCallback = (err: Error | null, config?: Configuration) => void;
607
+ export type ReadConfigCallback = (err: Error | null, config?: import("./configuration.d.ts").Configuration | undefined) => void;
597
608
  /**
598
609
  * Called with the result of the resolveConfigExtends function.
599
610
  */
600
- export type ResolveConfigExtendsCallback = (err: Error | null, path?: string) => void;
611
+ export type ResolveConfigExtendsCallback = (err: Error | null, path?: string | undefined) => void;
612
+ /**
613
+ * Rule configuration.
614
+ */
615
+ export type RuleConfiguration = boolean | any;
@@ -93,6 +93,7 @@ function validateRuleList(ruleList, synchronous) {
93
93
  }
94
94
  for (const tag of rule.tags) {
95
95
  const tagUpper = tag.toUpperCase();
96
+ // eslint-disable-next-line unicorn/no-computed-property-existence-check
96
97
  if (!result && allIds[tagUpper]) {
97
98
  result = new Error("Tag '" + tag + "' of custom rule at index " +
98
99
  customIndex + " is already used as a name.");
@@ -104,81 +105,6 @@ function validateRuleList(ruleList, synchronous) {
104
105
  return result;
105
106
  }
106
107
 
107
- /**
108
- * Creates a LintResults instance with toString for pretty display.
109
- *
110
- * @param {Rule[]} ruleList List of rules.
111
- * @returns {LintResults} New LintResults instance.
112
- */
113
- function newResults(ruleList) {
114
- /**
115
- * Returns the string representation of a LintResults instance.
116
- *
117
- * @param {boolean} useAlias True if rule alias should be used instead of name.
118
- * @returns {string} String representation of the instance.
119
- * @this {LintResults}
120
- */
121
- function toString(useAlias) {
122
- // eslint-disable-next-line consistent-this, unicorn/no-this-assignment
123
- const lintResults = this;
124
- /** @type {Object.<string, Rule> | null} */
125
- let ruleNameToRule = null;
126
- const results = [];
127
- const keys = Object.keys(lintResults);
128
- keys.sort();
129
- for (const file of keys) {
130
- const fileResults = lintResults[file];
131
- if (Array.isArray(fileResults)) {
132
- for (const result of fileResults) {
133
- const ruleMoniker = result.ruleNames ?
134
- result.ruleNames.join("/") :
135
- // @ts-ignore
136
- (result.ruleName + "/" + result.ruleAlias);
137
- results.push(
138
- file + ": " +
139
- result.lineNumber + ": " +
140
- ruleMoniker + " " +
141
- result.ruleDescription +
142
- (result.errorDetail ?
143
- " [" + result.errorDetail + "]" :
144
- "") +
145
- (result.errorContext ?
146
- " [Context: \"" + result.errorContext + "\"]" :
147
- ""));
148
- }
149
- } else {
150
- if (!ruleNameToRule) {
151
- ruleNameToRule = {};
152
- for (const rule of ruleList) {
153
- const ruleName = rule.names[0].toUpperCase();
154
- ruleNameToRule[ruleName] = rule;
155
- }
156
- }
157
- for (const [ ruleName, ruleResults ] of Object.entries(fileResults)) {
158
- const rule = ruleNameToRule[ruleName.toUpperCase()];
159
- for (const lineNumber of ruleResults) {
160
- // @ts-ignore
161
- const nameIndex = Math.min(useAlias ? 1 : 0, rule.names.length - 1);
162
- const result =
163
- file + ": " +
164
- lineNumber + ": " +
165
- // @ts-ignore
166
- rule.names[nameIndex] + " " +
167
- // @ts-ignore
168
- rule.description;
169
- results.push(result);
170
- }
171
- }
172
- }
173
- }
174
- return results.join("\n");
175
- }
176
- const lintResults = {};
177
- Object.defineProperty(lintResults, "toString", { "value": toString });
178
- // @ts-ignore
179
- return lintResults;
180
- }
181
-
182
108
  /**
183
109
  * Result object for removeFrontMatter.
184
110
  *
@@ -273,6 +199,7 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) {
273
199
  let ruleDefaultEnable = true;
274
200
  /** @type {"error" | "warning"} */
275
201
  let ruleDefaultSeverity = "error";
202
+ // eslint-disable-next-line unicorn/no-unused-array-method-return
276
203
  Object.entries(config).every(([ key, value ]) => {
277
204
  if (key.toUpperCase() === "DEFAULT") {
278
205
  ruleDefaultEnable = !!value;
@@ -513,6 +440,7 @@ function lintContent(
513
440
  // eslint-disable-next-line jsdoc/reject-any-type
514
441
  const callbackError = (/** @type {any} */ error) => callback(error instanceof Error ? error : new Error(error));
515
442
  // Remove UTF-8 byte order marker (if present)
443
+ // eslint-disable-next-line unicorn/prefer-unicode-code-point-escapes
516
444
  content = content.replace(/^\uFEFF/, "");
517
445
  // Remove front matter
518
446
  const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
@@ -574,7 +502,7 @@ function lintContent(
574
502
  cacheInitialize({
575
503
  ...paramsBase,
576
504
  "parsers": parsersMicromark,
577
- "config": null
505
+ "config": {}
578
506
  });
579
507
  // Function to run for each rule
580
508
  /** @type {LintError[]} */
@@ -845,8 +773,8 @@ function lintFile(
845
773
  */
846
774
  function lintInput(options, synchronous, callback) {
847
775
  // Normalize inputs
848
- options = options || {};
849
- callback = callback || function noop() {};
776
+ options ||= {};
777
+ callback ||= () => {};
850
778
  /** @type {Rule[]} */
851
779
  // @ts-ignore
852
780
  const customRuleList =
@@ -884,9 +812,6 @@ function lintInput(options, synchronous, callback) {
884
812
  options.frontMatter;
885
813
  const handleRuleFailures = !!options.handleRuleFailures;
886
814
  const noInlineConfig = !!options.noInlineConfig;
887
- // @ts-ignore
888
- // eslint-disable-next-line dot-notation
889
- const resultVersion = (options["resultVersion"] === undefined) ? 3 : options["resultVersion"];
890
815
  const markdownItFactory =
891
816
  options.markdownItFactory ||
892
817
  (() => { throw new Error("The option 'markdownItFactory' was required (due to the option 'customRules' including a rule requiring the 'markdown-it' parser), but 'markdownItFactory' was not set."); });
@@ -894,7 +819,7 @@ function lintInput(options, synchronous, callback) {
894
819
  // @ts-ignore
895
820
  const fs = options.fs || nodeFs;
896
821
  const aliasToRuleNames = mapAliasToRuleNames(ruleList);
897
- const results = newResults(ruleList);
822
+ const results = {};
898
823
  let done = false;
899
824
  let concurrency = 0;
900
825
  // eslint-disable-next-line jsdoc/require-jsdoc
@@ -952,18 +877,12 @@ function lintInput(options, synchronous, callback) {
952
877
  lintWorkerCallback
953
878
  );
954
879
  } else if (concurrency === 0) {
955
- // Finish
880
+ // Finished, sort keys for consistency
956
881
  done = true;
957
- // Deprecated: Convert results to specified resultVersion
958
- let convertedResults = results;
959
- if (resultVersion === 0) {
960
- convertedResults = helpers.convertToResultVersion0(results);
961
- } else if (resultVersion === 1) {
962
- convertedResults = helpers.convertToResultVersion1(results);
963
- } else if (resultVersion === 2) {
964
- convertedResults = helpers.convertToResultVersion2(results);
965
- }
966
- return callback(null, convertedResults);
882
+ const sortedEntries = Object.entries(results);
883
+ sortedEntries.sort(([ a ], [ b ]) => a.localeCompare(b));
884
+ const sortedResults = Object.fromEntries(sortedEntries);
885
+ return callback(null, sortedResults);
967
886
  }
968
887
  return null;
969
888
  }
@@ -1292,6 +1211,7 @@ export function applyFix(line, fixInfo, lineEnding = "\n") {
1292
1211
  const editIndex = editColumn - 1;
1293
1212
  return (deleteCount === -1) ?
1294
1213
  null :
1214
+ // eslint-disable-next-line unicorn/no-unsafe-string-replacement
1295
1215
  line.slice(0, editIndex) + insertText.replace(/\n/g, lineEnding) + line.slice(editIndex + deleteCount);
1296
1216
  }
1297
1217
 
@@ -1430,26 +1350,39 @@ export function getVersion() {
1430
1350
  */
1431
1351
 
1432
1352
  /**
1433
- * markdown-it token.
1353
+ * markdown-it base token.
1434
1354
  *
1435
- * @typedef {Object} MarkdownItToken
1436
- * @property {string[][]} attrs HTML attributes.
1355
+ * @typedef {Object} MarkdownItBaseToken
1356
+ * @property {string[][] | null} attrs HTML attributes.
1437
1357
  * @property {boolean} block Block-level token.
1438
- * @property {MarkdownItToken[]} children Child nodes.
1358
+ * @property {MarkdownItBaseToken[] | null} children Child nodes.
1439
1359
  * @property {string} content Tag contents.
1440
1360
  * @property {boolean} hidden Ignore element.
1441
1361
  * @property {string} info Fence info.
1442
1362
  * @property {number} level Nesting level.
1443
- * @property {number[]} map Beginning/ending line numbers.
1363
+ * @property {number[] | null} map Beginning/ending line numbers.
1444
1364
  * @property {string} markup Markup text.
1445
1365
  * @property {Object} meta Arbitrary data.
1446
1366
  * @property {number} nesting Level change.
1447
1367
  * @property {string} tag HTML tag name.
1448
1368
  * @property {string} type Token type.
1369
+ */
1370
+
1371
+ /**
1372
+ * markdown-it extended token.
1373
+ *
1374
+ * @typedef {Object} MarkdownItExtendedToken
1375
+ * @property {MarkdownItExtendedToken[] | null} children Child nodes.
1449
1376
  * @property {number} lineNumber Line number (1-based).
1450
1377
  * @property {string} line Line content.
1451
1378
  */
1452
1379
 
1380
+ /**
1381
+ * markdown-it token.
1382
+ *
1383
+ * @typedef {MarkdownItBaseToken & MarkdownItExtendedToken} MarkdownItToken
1384
+ */
1385
+
1453
1386
  /** @typedef {import("micromark-util-types").TokenType} MicromarkTokenType */
1454
1387
 
1455
1388
  /**
@@ -1515,7 +1448,7 @@ export function getVersion() {
1515
1448
  * @callback MarkdownItParse
1516
1449
  * @param {string} src Source string.
1517
1450
  * @param {Object} env Environment sandbox.
1518
- * @returns {import("markdown-it").Token[]} Tokens.
1451
+ * @returns {MarkdownItBaseToken[]} Tokens.
1519
1452
  */
1520
1453
 
1521
1454
  /**
@@ -1627,12 +1560,6 @@ export function getVersion() {
1627
1560
  * @typedef {import("./configuration-strict.d.ts").ConfigurationStrict} ConfigurationStrict
1628
1561
  */
1629
1562
 
1630
- /**
1631
- * Rule configuration object.
1632
- *
1633
- * @typedef {boolean | Object} RuleConfiguration Rule configuration.
1634
- */
1635
-
1636
1563
  /**
1637
1564
  * Parses a configuration string and returns a configuration object.
1638
1565
  *
@@ -1658,3 +1585,11 @@ export function getVersion() {
1658
1585
  * @param {string} [path] Resolved path to file.
1659
1586
  * @returns {void}
1660
1587
  */
1588
+
1589
+ /* eslint-disable jsdoc/reject-any-type */
1590
+
1591
+ /**
1592
+ * Rule configuration object.
1593
+ *
1594
+ * @typedef {boolean | any} RuleConfiguration Rule configuration.
1595
+ */
package/lib/md004.mjs CHANGED
@@ -40,6 +40,7 @@ export default {
40
40
  for (const listItemMarker of listItemMarkers) {
41
41
  const itemStyle = markerToStyle(listItemMarker.text);
42
42
  if (style === "sublist") {
43
+ // eslint-disable-next-line unicorn/no-computed-property-existence-check
43
44
  if (!nestingStyles[nesting]) {
44
45
  nestingStyles[nesting] =
45
46
  (itemStyle === nestingStyles[nesting - 1]) ?
package/lib/md005.mjs CHANGED
@@ -34,7 +34,7 @@ export default {
34
34
  } else {
35
35
  const markerLength = listItemPrefix.text.trim().length;
36
36
  const actualEnd = listItemPrefix.startColumn + markerLength - 1;
37
- expectedEnd = expectedEnd || actualEnd;
37
+ expectedEnd ||= actualEnd;
38
38
  if ((expectedIndent !== actualIndent) || endMatching) {
39
39
  if (expectedEnd === actualEnd) {
40
40
  endMatching = true;
@@ -16,6 +16,7 @@ function validateHeadingSpaces(onError, heading, delta) {
16
16
  const { children, startLine, text } = heading;
17
17
  let index = (delta > 0) ? 0 : (children.length - 1);
18
18
  while (
19
+ // eslint-disable-next-line unicorn/no-computed-property-existence-check
19
20
  children[index] &&
20
21
  (children[index].type !== "atxHeadingSequence")
21
22
  ) {