markdownlint 0.38.0 → 0.40.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 (60) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +144 -75
  4. package/doc/Rules.md +174 -18
  5. package/doc/md001.md +14 -0
  6. package/doc/md009.md +8 -9
  7. package/doc/md010.md +6 -0
  8. package/doc/md029.md +2 -0
  9. package/doc/md033.md +7 -1
  10. package/doc/md051.md +10 -5
  11. package/doc/md055.md +1 -1
  12. package/doc/md056.md +1 -1
  13. package/doc/md059.md +4 -1
  14. package/doc/md060.md +118 -0
  15. package/helpers/README.md +2 -2
  16. package/helpers/helpers.cjs +171 -15
  17. package/helpers/micromark-helpers.cjs +11 -7
  18. package/helpers/package.json +1 -1
  19. package/lib/cache.mjs +6 -2
  20. package/lib/configuration-strict.d.ts +1351 -205
  21. package/lib/constants.mjs +6 -5
  22. package/lib/defer-require.cjs +2 -0
  23. package/lib/exports.d.mts +1 -2
  24. package/lib/exports.mjs +1 -2
  25. package/lib/markdownit.cjs +2 -1
  26. package/lib/markdownlint.d.mts +101 -51
  27. package/lib/markdownlint.mjs +217 -181
  28. package/lib/md001.mjs +6 -2
  29. package/lib/md004.mjs +7 -18
  30. package/lib/md007.mjs +2 -1
  31. package/lib/md009.mjs +9 -5
  32. package/lib/md010.mjs +1 -1
  33. package/lib/md011.mjs +8 -6
  34. package/lib/md013.mjs +14 -27
  35. package/lib/md022.mjs +5 -2
  36. package/lib/md029.mjs +25 -14
  37. package/lib/md031.mjs +0 -1
  38. package/lib/md032.mjs +3 -1
  39. package/lib/md033.mjs +28 -20
  40. package/lib/md034.mjs +2 -1
  41. package/lib/md036.mjs +5 -3
  42. package/lib/md037.mjs +10 -7
  43. package/lib/md042.mjs +4 -2
  44. package/lib/md043.mjs +2 -2
  45. package/lib/md044.mjs +1 -1
  46. package/lib/md046.mjs +6 -6
  47. package/lib/md053.mjs +1 -1
  48. package/lib/md054.mjs +7 -5
  49. package/lib/md055.mjs +7 -6
  50. package/lib/md056.mjs +1 -1
  51. package/lib/md060.mjs +170 -0
  52. package/lib/micromark-parse.mjs +5 -3
  53. package/lib/node-imports-browser.mjs +2 -0
  54. package/lib/parse-configuration.mjs +5 -4
  55. package/lib/rules.mjs +3 -1
  56. package/package.json +18 -18
  57. package/schema/.markdownlint.jsonc +69 -54
  58. package/schema/.markdownlint.yaml +66 -53
  59. package/schema/markdownlint-config-schema-strict.json +4709 -1537
  60. package/schema/markdownlint-config-schema.json +4709 -1537
package/lib/md001.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- import { addErrorDetailIf } from "../helpers/helpers.cjs";
3
+ import { addErrorDetailIf, frontMatterHasTitle } from "../helpers/helpers.cjs";
4
4
  import { getHeadingLevel } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
@@ -11,7 +11,11 @@ export default {
11
11
  "tags": [ "headings" ],
12
12
  "parser": "micromark",
13
13
  "function": function MD001(params, onError) {
14
- let prevLevel = Number.MAX_SAFE_INTEGER;
14
+ const hasTitle = frontMatterHasTitle(
15
+ params.frontMatterLines,
16
+ params.config.front_matter_title
17
+ );
18
+ let prevLevel = hasTitle ? 1 : Number.MAX_SAFE_INTEGER;
15
19
  for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
16
20
  const level = getHeadingLevel(heading);
17
21
  if (level > prevLevel) {
package/lib/md004.mjs CHANGED
@@ -4,21 +4,9 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
4
  import { getDescendantsByType, getParentOfType } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
- const markerToStyle = {
8
- "-": "dash",
9
- "+": "plus",
10
- "*": "asterisk"
11
- };
12
- const styleToMarker = {
13
- "dash": "-",
14
- "plus": "+",
15
- "asterisk": "*"
16
- };
17
- const differentItemStyle = {
18
- "dash": "plus",
19
- "plus": "asterisk",
20
- "asterisk": "dash"
21
- };
7
+ const markerToStyle = (/** @type {string} */ marker) => (marker === "-") ? "dash" : ((marker === "+") ? "plus" : "asterisk");
8
+ const styleToMarker = (/** @type {string} */ style) => (style === "dash") ? "-" : ((style === "plus") ? "+" : "*");
9
+ const differentItemStyle = (/** @type {string} */ style) => (style === "dash") ? "plus" : ((style === "plus") ? "asterisk" : "dash");
22
10
  const validStyles = new Set([
23
11
  "asterisk",
24
12
  "consistent",
@@ -36,6 +24,7 @@ export default {
36
24
  "function": function MD004(params, onError) {
37
25
  const style = String(params.config.style || "consistent");
38
26
  let expectedStyle = validStyles.has(style) ? style : "dash";
27
+ /** @type {("asterisk"|"dash"|"plus")[]} */
39
28
  const nestingStyles = [];
40
29
  for (const listUnordered of filterByTypesCached([ "listUnordered" ])) {
41
30
  let nesting = 0;
@@ -49,12 +38,12 @@ export default {
49
38
  }
50
39
  const listItemMarkers = getDescendantsByType(listUnordered, [ "listItemPrefix", "listItemMarker" ]);
51
40
  for (const listItemMarker of listItemMarkers) {
52
- const itemStyle = markerToStyle[listItemMarker.text];
41
+ const itemStyle = markerToStyle(listItemMarker.text);
53
42
  if (style === "sublist") {
54
43
  if (!nestingStyles[nesting]) {
55
44
  nestingStyles[nesting] =
56
45
  (itemStyle === nestingStyles[nesting - 1]) ?
57
- differentItemStyle[itemStyle] :
46
+ differentItemStyle(itemStyle) :
58
47
  itemStyle;
59
48
  }
60
49
  expectedStyle = nestingStyles[nesting];
@@ -74,7 +63,7 @@ export default {
74
63
  {
75
64
  "editColumn": column,
76
65
  "deleteCount": length,
77
- "insertText": styleToMarker[expectedStyle]
66
+ "insertText": styleToMarker(expectedStyle)
78
67
  }
79
68
  );
80
69
  }
package/lib/md007.mjs CHANGED
@@ -53,8 +53,9 @@ export default {
53
53
  const nesting = unorderedListNesting.get(parent);
54
54
  if (nesting !== undefined) {
55
55
  // listItemPrefix for listUnordered
56
+ const baseIndent = (getParentOfType(token, [ "gfmFootnoteDefinition" ])) ? 4 : 0;
56
57
  const expectedIndent =
57
- (startIndented ? startIndent : 0) + (nesting * indent);
58
+ baseIndent + (startIndented ? startIndent : 0) + (nesting * indent);
58
59
  const blockQuoteAdjustment =
59
60
  (lastBlockQuotePrefix?.endLine === startLine) ?
60
61
  (lastBlockQuotePrefix.endColumn - 1) :
package/lib/md009.mjs CHANGED
@@ -13,14 +13,18 @@ export default {
13
13
  "function": function MD009(params, onError) {
14
14
  let brSpaces = params.config.br_spaces;
15
15
  brSpaces = Number((brSpaces === undefined) ? 2 : brSpaces);
16
+ const codeBlocks = params.config.code_blocks;
17
+ const includeCode = (codeBlocks === undefined) ? false : !!codeBlocks;
16
18
  const listItemEmptyLines = !!params.config.list_item_empty_lines;
17
19
  const strict = !!params.config.strict;
18
20
  const codeBlockLineNumbers = new Set();
19
- for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
20
- addRangeToSet(codeBlockLineNumbers, codeBlock.startLine + 1, codeBlock.endLine - 1);
21
- }
22
- for (const codeBlock of filterByTypesCached([ "codeIndented" ])) {
23
- addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
21
+ if (!includeCode) {
22
+ for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
23
+ addRangeToSet(codeBlockLineNumbers, codeBlock.startLine + 1, codeBlock.endLine - 1);
24
+ }
25
+ for (const codeBlock of filterByTypesCached([ "codeIndented" ])) {
26
+ addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
27
+ }
24
28
  }
25
29
  const listItemLineNumbers = new Set();
26
30
  if (listItemEmptyLines) {
package/lib/md010.mjs CHANGED
@@ -17,7 +17,7 @@ export default {
17
17
  const includeCode = (codeBlocks === undefined) ? true : !!codeBlocks;
18
18
  const ignoreCodeLanguages = new Set(
19
19
  (params.config.ignore_code_languages || [])
20
- .map((language) => language.toLowerCase())
20
+ .map((/** @type {void} */ language) => String(language).toLowerCase())
21
21
  );
22
22
  const spacesPerTab = params.config.spaces_per_tab;
23
23
  const spaceMultiplier = (spacesPerTab === undefined) ?
package/lib/md011.mjs CHANGED
@@ -4,6 +4,8 @@ import { addError, hasOverlap } from "../helpers/helpers.cjs";
4
4
  import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
+ /** @typedef {import("micromark-extension-math")} */
8
+
7
9
  const reversedLinkRe = /(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;
8
10
 
9
11
  /** @type {import("markdownlint").Rule} */
@@ -13,14 +15,14 @@ export default {
13
15
  "tags": [ "links" ],
14
16
  "parser": "micromark",
15
17
  "function": function MD011(params, onError) {
16
- const codeBlockLineNumbers = new Set();
17
- for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
18
- addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
18
+ const ignoreBlockLineNumbers = new Set();
19
+ for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "mathFlow" ])) {
20
+ addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
19
21
  }
20
- const codeTexts = filterByTypesCached([ "codeText" ]);
22
+ const ignoreTexts = filterByTypesCached([ "codeText", "mathText" ]);
21
23
  for (const [ lineIndex, line ] of params.lines.entries()) {
22
24
  const lineNumber = lineIndex + 1;
23
- if (!codeBlockLineNumbers.has(lineNumber)) {
25
+ if (!ignoreBlockLineNumbers.has(lineNumber)) {
24
26
  let match = null;
25
27
  while ((match = reversedLinkRe.exec(line)) !== null) {
26
28
  const [ reversedLink, preChar, linkText, linkDestination ] = match;
@@ -32,7 +34,7 @@ export default {
32
34
  const length = match[0].length - preChar.length;
33
35
  /** @type {import("../helpers/helpers.cjs").FileRange} */
34
36
  const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
35
- if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) {
37
+ if (!ignoreTexts.some((ignoreText) => hasOverlap(ignoreText, range))) {
36
38
  addError(
37
39
  onError,
38
40
  lineNumber,
package/lib/md013.mjs CHANGED
@@ -4,10 +4,8 @@ import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
4
  import { filterByTypesCached, getReferenceLinkImageData } from "./cache.mjs";
5
5
  import { addRangeToSet, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
6
6
 
7
- const longLineRePrefix = "^.{";
8
- const longLineRePostfixRelaxed = "}.*\\s.*$";
9
- const longLineRePostfixStrict = "}.+$";
10
- const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
7
+ // Regular expression for a line that is not wrappable
8
+ const notWrappableRe = /^(?:[#>\s]*\s)?\S*$/;
11
9
 
12
10
  /** @typedef {import("micromark-extension-gfm-autolink-literal")} */
13
11
  /** @typedef {import("micromark-extension-gfm-table")} */
@@ -20,20 +18,10 @@ export default {
20
18
  "parser": "micromark",
21
19
  "function": function MD013(params, onError) {
22
20
  const lineLength = Number(params.config.line_length || 80);
23
- const headingLineLength =
24
- Number(params.config.heading_line_length || lineLength);
25
- const codeLineLength =
26
- Number(params.config.code_block_line_length || lineLength);
21
+ const headingLineLength = Number(params.config.heading_line_length || lineLength);
22
+ const codeLineLength = Number(params.config.code_block_line_length || lineLength);
27
23
  const strict = !!params.config.strict;
28
24
  const stern = !!params.config.stern;
29
- const longLineRePostfix =
30
- (strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed;
31
- const longLineRe =
32
- new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
33
- const longHeadingLineRe =
34
- new RegExp(longLineRePrefix + headingLineLength + longLineRePostfix);
35
- const longCodeLineRe =
36
- new RegExp(longLineRePrefix + codeLineLength + longLineRePostfix);
37
25
  const codeBlocks = params.config.code_blocks;
38
26
  const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
39
27
  const tables = params.config.tables;
@@ -75,28 +63,27 @@ export default {
75
63
  const isHeading = headingLineNumbers.has(lineNumber);
76
64
  const inCode = codeBlockLineNumbers.has(lineNumber);
77
65
  const inTable = tableLineNumbers.has(lineNumber);
78
- const length = inCode ?
79
- codeLineLength :
80
- (isHeading ? headingLineLength : lineLength);
81
- const lengthRe = inCode ?
82
- longCodeLineRe :
83
- (isHeading ? longHeadingLineRe : longLineRe);
84
- if ((includeCodeBlocks || !inCode) &&
66
+ const maxLength = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength);
67
+ // If not strict/stern, the last run of non-whitespace is allowed to go
68
+ // beyond the limit as long as it begins within the limit
69
+ const text = (strict || stern) ? line : line.replace(/\S*$/u, "#");
70
+ if ((maxLength > 0) &&
71
+ (includeCodeBlocks || !inCode) &&
85
72
  (includeTables || !inTable) &&
86
73
  (includeHeadings || !isHeading) &&
87
74
  !definitionLineIndices.has(lineIndex) &&
88
75
  (strict ||
89
- (!(stern && sternModeRe.test(line)) &&
76
+ (!(stern && notWrappableRe.test(line)) &&
90
77
  !linkOnlyLineNumbers.has(lineNumber))) &&
91
- lengthRe.test(line)) {
78
+ (text.length > maxLength)) {
92
79
  addErrorDetailIf(
93
80
  onError,
94
81
  lineNumber,
95
- length,
82
+ maxLength,
96
83
  line.length,
97
84
  undefined,
98
85
  undefined,
99
- [ length + 1, line.length - length ]
86
+ [ maxLength + 1, line.length - maxLength ]
100
87
  );
101
88
  }
102
89
  }
package/lib/md022.mjs CHANGED
@@ -4,15 +4,18 @@ import { addErrorDetailIf, isBlankLine } from "../helpers/helpers.cjs";
4
4
  import { getBlockQuotePrefixText, getHeadingLevel } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
8
+
7
9
  const defaultLines = 1;
8
10
 
9
- const getLinesFunction = (linesParam) => {
11
+ // eslint-disable-next-line jsdoc/reject-any-type
12
+ const getLinesFunction = (/** @type {any} */ linesParam) => {
10
13
  if (Array.isArray(linesParam)) {
11
14
  const linesArray = new Array(6).fill(defaultLines);
12
15
  for (const [ index, value ] of [ ...linesParam.entries() ].slice(0, 6)) {
13
16
  linesArray[index] = value;
14
17
  }
15
- return (heading) => linesArray[getHeadingLevel(heading) - 1];
18
+ return (/** @type {MicromarkToken} */ heading) => linesArray[getHeadingLevel(heading) - 1];
16
19
  }
17
20
  // Coerce linesParam to a number
18
21
  const lines = (linesParam === undefined) ? defaultLines : Number(linesParam);
package/lib/md029.mjs CHANGED
@@ -11,13 +11,17 @@ const listStyleExamples = {
11
11
  };
12
12
 
13
13
  /**
14
- * Gets the value of an ordered list item prefix token.
14
+ * Gets the column and text of an ordered list item prefix token.
15
15
  *
16
16
  * @param {import("markdownlint").MicromarkToken} listItemPrefix List item prefix token.
17
- * @returns {number} List item value.
17
+ * @returns {{column: number, value: number}} List item value column and text.
18
18
  */
19
19
  function getOrderedListItemValue(listItemPrefix) {
20
- return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
20
+ const listItemValue = getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0];
21
+ return {
22
+ "column": listItemValue.startColumn,
23
+ "value": Number(listItemValue.text)
24
+ };
21
25
  }
22
26
 
23
27
  /** @type {import("markdownlint").Rule} */
@@ -27,34 +31,40 @@ export default {
27
31
  "tags": [ "ol" ],
28
32
  "parser": "micromark",
29
33
  "function": function MD029(params, onError) {
30
- const style = String(params.config.style || "one_or_ordered");
34
+ const style = String(params.config.style);
31
35
  for (const listOrdered of filterByTypesCached([ "listOrdered" ])) {
32
36
  const listItemPrefixes = getDescendantsByType(listOrdered, [ "listItemPrefix" ]);
33
37
  let expected = 1;
34
38
  let incrementing = false;
35
39
  // Check for incrementing number pattern 1/2/3 or 0/1/2
36
40
  if (listItemPrefixes.length >= 2) {
37
- const firstValue = getOrderedListItemValue(listItemPrefixes[0]);
38
- const secondValue = getOrderedListItemValue(listItemPrefixes[1]);
39
- if ((secondValue !== 1) || (firstValue === 0)) {
41
+ const first = getOrderedListItemValue(listItemPrefixes[0]);
42
+ const second = getOrderedListItemValue(listItemPrefixes[1]);
43
+ if ((second.value !== 1) || (first.value === 0)) {
40
44
  incrementing = true;
41
- if (firstValue === 0) {
45
+ if (first.value === 0) {
42
46
  expected = 0;
43
47
  }
44
48
  }
45
49
  }
46
50
  // Determine effective style
47
- let listStyle = style;
48
- if (listStyle === "one_or_ordered") {
49
- listStyle = incrementing ? "ordered" : "one";
50
- } else if (listStyle === "zero") {
51
+ const listStyle = ((style === "one") || (style === "ordered") || (style === "zero")) ?
52
+ style :
53
+ (incrementing ? "ordered" : "one");
54
+ if (listStyle === "zero") {
51
55
  expected = 0;
52
56
  } else if (listStyle === "one") {
53
57
  expected = 1;
54
58
  }
55
59
  // Validate each list item marker
56
60
  for (const listItemPrefix of listItemPrefixes) {
57
- const actual = getOrderedListItemValue(listItemPrefix);
61
+ const orderedListItemValue = getOrderedListItemValue(listItemPrefix);
62
+ const actual = orderedListItemValue.value;
63
+ const fixInfo = {
64
+ "editColumn": orderedListItemValue.column,
65
+ "deleteCount": orderedListItemValue.value.toString().length,
66
+ "insertText": expected.toString()
67
+ };
58
68
  addErrorDetailIf(
59
69
  onError,
60
70
  listItemPrefix.startLine,
@@ -62,7 +72,8 @@ export default {
62
72
  actual,
63
73
  "Style: " + listStyleExamples[listStyle],
64
74
  undefined,
65
- [ listItemPrefix.startColumn, listItemPrefix.endColumn - listItemPrefix.startColumn ]
75
+ [ listItemPrefix.startColumn, listItemPrefix.endColumn - listItemPrefix.startColumn ],
76
+ fixInfo
66
77
  );
67
78
  if (listStyle === "ordered") {
68
79
  expected++;
package/lib/md031.mjs CHANGED
@@ -6,7 +6,6 @@ import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
7
  const codeFencePrefixRe = /^(.*?)[`~]/;
8
8
 
9
- // eslint-disable-next-line jsdoc/valid-types
10
9
  /** @typedef {readonly string[]} ReadonlyStringArray */
11
10
 
12
11
  /**
package/lib/md032.mjs CHANGED
@@ -4,7 +4,9 @@ import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
4
4
  import { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
- const isList = (token) => (
7
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
8
+
9
+ const isList = (/** @type {MicromarkToken} */ token) => (
8
10
  (token.type === "listOrdered") || (token.type === "listUnordered")
9
11
  );
10
12
 
package/lib/md033.mjs CHANGED
@@ -1,9 +1,14 @@
1
1
  // @ts-check
2
2
 
3
3
  import { addError, nextLinesRe } from "../helpers/helpers.cjs";
4
- import { getHtmlTagInfo } from "../helpers/micromark-helpers.cjs";
4
+ import { getHtmlTagInfo, getParentOfType } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
+ /** @typedef {import("micromark-extension-gfm-table")} */
8
+
9
+ // eslint-disable-next-line jsdoc/reject-any-type
10
+ const toLowerCaseStringArray = (/** @type {any} */ arr) => Array.isArray(arr) ? arr.map((elm) => String(elm).toLowerCase()) : [];
11
+
7
12
  /** @type {import("markdownlint").Rule} */
8
13
  export default {
9
14
  "names": [ "MD033", "no-inline-html" ],
@@ -11,27 +16,30 @@ export default {
11
16
  "tags": [ "html" ],
12
17
  "parser": "micromark",
13
18
  "function": function MD033(params, onError) {
14
- let allowedElements = params.config.allowed_elements;
15
- allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
16
- allowedElements = allowedElements.map((element) => element.toLowerCase());
19
+ const allowedElements = toLowerCaseStringArray(params.config.allowed_elements);
20
+ // If not defined, use allowedElements for backward compatibility
21
+ const tableAllowedElements = toLowerCaseStringArray(params.config.table_allowed_elements || params.config.allowed_elements);
17
22
  for (const token of filterByTypesCached([ "htmlText" ], true)) {
18
23
  const htmlTagInfo = getHtmlTagInfo(token);
19
- if (
20
- htmlTagInfo &&
21
- !htmlTagInfo.close &&
22
- !allowedElements.includes(htmlTagInfo.name.toLowerCase())
23
- ) {
24
- const range = [
25
- token.startColumn,
26
- token.text.replace(nextLinesRe, "").length
27
- ];
28
- addError(
29
- onError,
30
- token.startLine,
31
- "Element: " + htmlTagInfo.name,
32
- undefined,
33
- range
34
- );
24
+ if (htmlTagInfo && !htmlTagInfo.close) {
25
+ const elementName = htmlTagInfo?.name.toLowerCase();
26
+ const inTable = !!getParentOfType(token, [ "table" ]);
27
+ if (
28
+ (inTable || !allowedElements.includes(elementName)) &&
29
+ (!inTable || !tableAllowedElements.includes(elementName))
30
+ ) {
31
+ const range = [
32
+ token.startColumn,
33
+ token.text.replace(nextLinesRe, "").length
34
+ ];
35
+ addError(
36
+ onError,
37
+ token.startLine,
38
+ "Element: " + htmlTagInfo.name,
39
+ undefined,
40
+ range
41
+ );
42
+ }
35
43
  }
36
44
  }
37
45
  }
package/lib/md034.mjs CHANGED
@@ -3,6 +3,7 @@
3
3
  import { addErrorContext } from "../helpers/helpers.cjs";
4
4
  import { filterByPredicate, getHtmlTagInfo, inHtmlFlow } from "../helpers/micromark-helpers.cjs";
5
5
 
6
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
6
7
  /** @typedef {import("micromark-extension-gfm-autolink-literal")} */
7
8
 
8
9
  /** @type {import("markdownlint").Rule} */
@@ -12,7 +13,7 @@ export default {
12
13
  "tags": [ "links", "url" ],
13
14
  "parser": "micromark",
14
15
  "function": function MD034(params, onError) {
15
- const literalAutolinks = (tokens) => (
16
+ const literalAutolinks = (/** @type {MicromarkToken[]} */ tokens) => (
16
17
  filterByPredicate(
17
18
  tokens,
18
19
  (token) => {
package/lib/md036.mjs CHANGED
@@ -4,14 +4,16 @@ import { addErrorContext, allPunctuation } from "../helpers/helpers.cjs";
4
4
  import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
5
  import { filterByTypesCached } from "./cache.mjs";
6
6
 
7
- /** @typedef {import("markdownlint").MicromarkTokenType} TokenType */
8
- /** @type {TokenType[][]} */
7
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
8
+ /** @typedef {import("markdownlint").MicromarkTokenType} MicromarkTokenType */
9
+
10
+ /** @type {MicromarkTokenType[][]} */
9
11
  const emphasisTypes = [
10
12
  [ "emphasis", "emphasisText" ],
11
13
  [ "strong", "strongText" ]
12
14
  ];
13
15
 
14
- const isParagraphChildMeaningful = (token) => !(
16
+ const isParagraphChildMeaningful = (/** @type {MicromarkToken} */ token) => !(
15
17
  (token.type === "htmlText") ||
16
18
  ((token.type === "data") && (token.text.trim().length === 0))
17
19
  );
package/lib/md037.mjs CHANGED
@@ -50,15 +50,17 @@ export default {
50
50
  if (startMatch) {
51
51
  const [ startSpaceCharacter ] = startMatch;
52
52
  const startContext = `${marker}${startSpaceCharacter}`;
53
+ const column = startToken.endColumn;
54
+ const count = startSpaceCharacter.length - 1;
53
55
  addError(
54
56
  onError,
55
57
  startToken.startLine,
56
58
  undefined,
57
59
  startContext,
58
- [ startToken.startColumn, startContext.length ],
60
+ [ column, count ],
59
61
  {
60
- "editColumn": startToken.endColumn,
61
- "deleteCount": startSpaceCharacter.length - 1
62
+ "editColumn": column,
63
+ "deleteCount": count
62
64
  }
63
65
  );
64
66
  }
@@ -71,16 +73,17 @@ export default {
71
73
  if (endMatch) {
72
74
  const [ endSpaceCharacter ] = endMatch;
73
75
  const endContext = `${endSpaceCharacter}${marker}`;
76
+ const column = endToken.startColumn - (endSpaceCharacter.length - 1);
77
+ const count = endSpaceCharacter.length - 1;
74
78
  addError(
75
79
  onError,
76
80
  endToken.startLine,
77
81
  undefined,
78
82
  endContext,
79
- [ endToken.endColumn - endContext.length, endContext.length ],
83
+ [ column, count ],
80
84
  {
81
- "editColumn":
82
- endToken.startColumn - (endSpaceCharacter.length - 1),
83
- "deleteCount": endSpaceCharacter.length - 1
85
+ "editColumn": column,
86
+ "deleteCount": count
84
87
  }
85
88
  );
86
89
  }
package/lib/md042.mjs CHANGED
@@ -4,6 +4,8 @@ import { addErrorContext } from "../helpers/helpers.cjs";
4
4
  import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
5
  import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
6
6
 
7
+ /** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
8
+
7
9
  /** @type {import("markdownlint").Rule} */
8
10
  export default {
9
11
  "names": [ "MD042", "no-empty-links" ],
@@ -12,9 +14,9 @@ export default {
12
14
  "parser": "micromark",
13
15
  "function": function MD042(params, onError) {
14
16
  const { definitions } = getReferenceLinkImageData();
15
- const isReferenceDefinitionHash = (token) => {
17
+ const isReferenceDefinitionHash = (/** @type {MicromarkToken} */ token) => {
16
18
  const definition = definitions.get(token.text.trim());
17
- return (definition && (definition[1] === "#"));
19
+ return Boolean(definition && (definition[1] === "#"));
18
20
  };
19
21
  const links = filterByTypesCached([ "link" ]);
20
22
  for (const link of links) {
package/lib/md043.mjs CHANGED
@@ -21,8 +21,8 @@ export default {
21
21
  let matchAny = false;
22
22
  let hasError = false;
23
23
  let anyHeadings = false;
24
- const getExpected = () => requiredHeadings[i++] || "[None]";
25
- const handleCase = (str) => (matchCase ? str : str.toLowerCase());
24
+ const getExpected = () => String(requiredHeadings[i++] || "[None]");
25
+ const handleCase = (/** @type {string} */ str) => (matchCase ? str : str.toLowerCase());
26
26
  for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
27
27
  if (!hasError) {
28
28
  const headingText = getHeadingText(heading);
package/lib/md044.mjs CHANGED
@@ -17,7 +17,7 @@ export default {
17
17
  "function": function MD044(params, onError) {
18
18
  let names = params.config.names;
19
19
  names = Array.isArray(names) ? names : [];
20
- names.sort((a, b) => (b.length - a.length) || a.localeCompare(b));
20
+ names.sort((/** @type {string} */ a, /** @type {string} */ b) => (b.length - a.length) || a.localeCompare(b));
21
21
  if (names.length === 0) {
22
22
  // Nothing to check; avoid doing any work
23
23
  return;
package/lib/md046.mjs CHANGED
@@ -3,10 +3,9 @@
3
3
  import { addErrorDetailIf } from "../helpers/helpers.cjs";
4
4
  import { filterByTypesCached } from "./cache.mjs";
5
5
 
6
- const tokenTypeToStyle = {
7
- "codeFenced": "fenced",
8
- "codeIndented": "indented"
9
- };
6
+ /** @typedef {import("markdownlint").MicromarkTokenType} MicromarkTokenType */
7
+
8
+ const tokenTypeToStyle = (/** @type {MicromarkTokenType} */ tokenType) => (tokenType === "codeFenced") ? "fenced" : "indented";
10
9
 
11
10
  /** @type {import("markdownlint").Rule} */
12
11
  export default {
@@ -19,13 +18,14 @@ export default {
19
18
  for (const token of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
20
19
  const { startLine, type } = token;
21
20
  if (expectedStyle === "consistent") {
22
- expectedStyle = tokenTypeToStyle[type];
21
+ expectedStyle = tokenTypeToStyle(type);
23
22
  }
24
23
  addErrorDetailIf(
25
24
  onError,
26
25
  startLine,
27
26
  expectedStyle,
28
- tokenTypeToStyle[type]);
27
+ tokenTypeToStyle(type)
28
+ );
29
29
  }
30
30
  }
31
31
  };
package/lib/md053.mjs CHANGED
@@ -16,7 +16,7 @@ export default {
16
16
  const lines = params.lines;
17
17
  const { references, shortcuts, definitions, duplicateDefinitions } =
18
18
  getReferenceLinkImageData();
19
- const singleLineDefinition = (line) => (
19
+ const singleLineDefinition = (/** @type {string} */ line) => (
20
20
  line.replace(linkReferenceDefinitionRe, "").trim().length > 0
21
21
  );
22
22
  const deleteFixInfo = {
package/lib/md054.mjs CHANGED
@@ -5,9 +5,9 @@ import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
5
5
  import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
6
6
 
7
7
  const backslashEscapeRe = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
8
- const removeBackslashEscapes = (text) => text.replace(backslashEscapeRe, "$1");
8
+ const removeBackslashEscapes = (/** @type {string} **/ text) => text.replace(backslashEscapeRe, "$1");
9
9
  const autolinkDisallowedRe = /[ <>]/;
10
- const autolinkAble = (destination) => {
10
+ const autolinkAble = (/** @type {string} */ destination) => {
11
11
  try {
12
12
  // eslint-disable-next-line no-new
13
13
  new URL(destination);
@@ -73,9 +73,11 @@ export default {
73
73
  const referenceString = getDescendantsByType(link, [ "reference", "referenceString" ])[0]?.text;
74
74
  const isCollapsed = (referenceString === undefined);
75
75
  const definition = definitions.get(referenceString || label);
76
- destination = definition && definition[1];
77
- isError = destination &&
78
- (isShortcut ? !shortcut : (isCollapsed ? !collapsed : !full));
76
+ destination = (definition && definition[1]) || "";
77
+ isError = Boolean(
78
+ destination &&
79
+ (isShortcut ? !shortcut : (isCollapsed ? !collapsed : !full))
80
+ );
79
81
  }
80
82
  }
81
83
  if (isError) {