markdownlint 0.37.4 → 0.39.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.
- package/CHANGELOG.md +20 -0
- package/CONTRIBUTING.md +2 -3
- package/README.md +175 -87
- package/doc/Rules.md +273 -47
- package/doc/md001.md +14 -0
- package/doc/md009.md +8 -9
- package/doc/md010.md +6 -0
- package/doc/md027.md +8 -0
- package/doc/md029.md +2 -0
- package/doc/md033.md +7 -1
- package/doc/md038.md +23 -11
- package/doc/md041.md +31 -16
- package/doc/md043.md +22 -4
- package/doc/md045.md +9 -1
- package/doc/md051.md +17 -0
- package/doc/md052.md +12 -0
- package/doc/md053.md +3 -3
- package/doc/md055.md +1 -1
- package/doc/md056.md +1 -1
- package/doc/md059.md +33 -0
- package/doc/md060.md +70 -0
- package/helpers/README.md +2 -2
- package/helpers/helpers.cjs +174 -20
- package/helpers/micromark-helpers.cjs +37 -7
- package/helpers/package.json +1 -1
- package/lib/cache.mjs +25 -7
- package/lib/configuration-strict.d.ts +1494 -292
- package/lib/constants.mjs +6 -5
- package/lib/defer-require.cjs +2 -0
- package/lib/exports.d.mts +2 -2
- package/lib/exports.mjs +2 -2
- package/lib/markdownit.cjs +8 -14
- package/lib/markdownlint.d.mts +136 -52
- package/lib/markdownlint.mjs +469 -409
- package/lib/md001.mjs +6 -2
- package/lib/md004.mjs +7 -18
- package/lib/md007.mjs +2 -1
- package/lib/md009.mjs +9 -5
- package/lib/md010.mjs +1 -1
- package/lib/md022.mjs +5 -2
- package/lib/md025.mjs +23 -15
- package/lib/md027.mjs +11 -1
- package/lib/md029.mjs +25 -14
- package/lib/md031.mjs +0 -1
- package/lib/md032.mjs +3 -1
- package/lib/md033.mjs +28 -20
- package/lib/md034.mjs +2 -1
- package/lib/md036.mjs +16 -4
- package/lib/md037.mjs +10 -7
- package/lib/md038.mjs +52 -71
- package/lib/md041.mjs +54 -16
- package/lib/md042.mjs +4 -2
- package/lib/md043.mjs +4 -2
- package/lib/md044.mjs +1 -1
- package/lib/md045.mjs +3 -1
- package/lib/md046.mjs +6 -6
- package/lib/md051.mjs +13 -5
- package/lib/md052.mjs +2 -1
- package/lib/md053.mjs +1 -1
- package/lib/md054.mjs +7 -5
- package/lib/md055.mjs +7 -6
- package/lib/md056.mjs +1 -1
- package/lib/md059.mjs +71 -0
- package/lib/md060.mjs +121 -0
- package/lib/micromark-parse.mjs +17 -3
- package/lib/node-imports-browser.mjs +2 -0
- package/lib/parse-configuration.mjs +47 -0
- package/lib/rules.mjs +5 -1
- package/package.json +32 -30
- package/schema/.markdownlint.jsonc +97 -62
- package/schema/.markdownlint.yaml +86 -57
- package/schema/markdownlint-config-schema-strict.json +4713 -1436
- package/schema/markdownlint-config-schema.json +4713 -1436
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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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/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
|
-
|
|
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/md025.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { addErrorContext, frontMatterHasTitle } from "../helpers/helpers.cjs";
|
|
4
|
-
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
|
|
4
|
+
import { getHeadingLevel, getHeadingText, isDocfxTab, isHtmlFlowComment, nonContentTokens } from "../helpers/micromark-helpers.cjs";
|
|
5
5
|
import { filterByTypesCached } from "./cache.mjs";
|
|
6
6
|
|
|
7
7
|
/** @type {import("markdownlint").Rule} */
|
|
@@ -12,24 +12,32 @@ export default {
|
|
|
12
12
|
"parser": "micromark",
|
|
13
13
|
"function": function MD025(params, onError) {
|
|
14
14
|
const level = Number(params.config.level || 1);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const { tokens } = params.parsers.micromark;
|
|
16
|
+
const matchingHeadings = filterByTypesCached([ "atxHeading", "setextHeading" ])
|
|
17
|
+
.filter((heading) => (level === getHeadingLevel(heading)) && !isDocfxTab(heading));
|
|
18
|
+
if (matchingHeadings.length > 0) {
|
|
19
|
+
const foundFrontMatterTitle =
|
|
20
|
+
frontMatterHasTitle(
|
|
21
|
+
params.frontMatterLines,
|
|
22
|
+
params.config.front_matter_title
|
|
23
|
+
);
|
|
24
|
+
// Front matter title counts as a top-level heading if present
|
|
25
|
+
let hasTopLevelHeading = foundFrontMatterTitle;
|
|
26
|
+
if (!hasTopLevelHeading) {
|
|
27
|
+
// Check if the first matching heading is a top-level heading
|
|
28
|
+
const previousTokens = tokens.slice(0, tokens.indexOf(matchingHeadings[0]));
|
|
29
|
+
hasTopLevelHeading = previousTokens.every(
|
|
30
|
+
(token) => nonContentTokens.has(token.type) || isHtmlFlowComment(token)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (hasTopLevelHeading) {
|
|
34
|
+
// All other matching headings are violations
|
|
35
|
+
for (const heading of matchingHeadings.slice(foundFrontMatterTitle ? 0 : 1)) {
|
|
26
36
|
addErrorContext(
|
|
27
37
|
onError,
|
|
28
38
|
heading.startLine,
|
|
29
|
-
|
|
39
|
+
getHeadingText(heading)
|
|
30
40
|
);
|
|
31
|
-
} else if (heading.startLine === 1) {
|
|
32
|
-
hasTopLevelHeading = true;
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
}
|
package/lib/md027.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { addErrorContext } from "../helpers/helpers.cjs";
|
|
4
|
+
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
|
|
4
5
|
import { filterByTypesCached } from "./cache.mjs";
|
|
5
6
|
|
|
7
|
+
/** @type {import("../helpers/micromark-helpers.cjs").TokenType[]} */
|
|
8
|
+
const listTypes = [ "listOrdered", "listUnordered" ];
|
|
9
|
+
|
|
6
10
|
/** @type {import("markdownlint").Rule} */
|
|
7
11
|
export default {
|
|
8
12
|
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
|
@@ -10,6 +14,8 @@ export default {
|
|
|
10
14
|
"tags": [ "blockquote", "whitespace", "indentation" ],
|
|
11
15
|
"parser": "micromark",
|
|
12
16
|
"function": function MD027(params, onError) {
|
|
17
|
+
const listItems = params.config.list_items;
|
|
18
|
+
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
|
13
19
|
const { tokens } = params.parsers.micromark;
|
|
14
20
|
for (const token of filterByTypesCached([ "linePrefix" ])) {
|
|
15
21
|
const parent = token.parent;
|
|
@@ -17,7 +23,11 @@ export default {
|
|
|
17
23
|
const siblings = parent?.children || tokens;
|
|
18
24
|
if (
|
|
19
25
|
!codeIndented &&
|
|
20
|
-
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix")
|
|
26
|
+
(siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") &&
|
|
27
|
+
(includeListItems || (
|
|
28
|
+
!listTypes.includes(siblings[siblings.indexOf(token) + 1]?.type) &&
|
|
29
|
+
!getParentOfType(token, listTypes)
|
|
30
|
+
))
|
|
21
31
|
) {
|
|
22
32
|
const { startColumn, startLine, text } = token;
|
|
23
33
|
const { length } = text;
|
package/lib/md029.mjs
CHANGED
|
@@ -11,13 +11,17 @@ const listStyleExamples = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Gets the
|
|
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
|
-
|
|
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
|
|
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
|
|
38
|
-
const
|
|
39
|
-
if ((
|
|
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 (
|
|
45
|
+
if (first.value === 0) {
|
|
42
46
|
expected = 0;
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
// Determine effective style
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
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
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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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,13 +4,20 @@ 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").
|
|
8
|
-
/** @
|
|
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
|
|
|
16
|
+
const isParagraphChildMeaningful = (/** @type {MicromarkToken} */ token) => !(
|
|
17
|
+
(token.type === "htmlText") ||
|
|
18
|
+
((token.type === "data") && (token.text.trim().length === 0))
|
|
19
|
+
);
|
|
20
|
+
|
|
14
21
|
/** @type {import("markdownlint").Rule} */
|
|
15
22
|
export default {
|
|
16
23
|
"names": [ "MD036", "no-emphasis-as-heading" ],
|
|
@@ -22,9 +29,14 @@ export default {
|
|
|
22
29
|
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
|
23
30
|
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
|
24
31
|
const paragraphTokens =
|
|
25
|
-
filterByTypesCached([ "paragraph" ])
|
|
32
|
+
filterByTypesCached([ "paragraph" ], true)
|
|
26
33
|
.filter((token) =>
|
|
27
|
-
(token.parent?.type === "content") &&
|
|
34
|
+
(token.parent?.type === "content") &&
|
|
35
|
+
(
|
|
36
|
+
!token.parent?.parent ||
|
|
37
|
+
((token.parent?.parent?.type === "htmlFlow") && !token.parent?.parent?.parent)
|
|
38
|
+
) &&
|
|
39
|
+
(token.children.filter(isParagraphChildMeaningful).length === 1)
|
|
28
40
|
);
|
|
29
41
|
for (const emphasisType of emphasisTypes) {
|
|
30
42
|
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
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
|
-
[
|
|
60
|
+
[ column, count ],
|
|
59
61
|
{
|
|
60
|
-
"editColumn":
|
|
61
|
-
"deleteCount":
|
|
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
|
-
[
|
|
83
|
+
[ column, count ],
|
|
80
84
|
{
|
|
81
|
-
"editColumn":
|
|
82
|
-
|
|
83
|
-
"deleteCount": endSpaceCharacter.length - 1
|
|
85
|
+
"editColumn": column,
|
|
86
|
+
"deleteCount": count
|
|
84
87
|
}
|
|
85
88
|
);
|
|
86
89
|
}
|
package/lib/md038.mjs
CHANGED
|
@@ -4,19 +4,6 @@ import { addErrorContext } from "../helpers/helpers.cjs";
|
|
|
4
4
|
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
|
|
5
5
|
import { filterByTypesCached } from "./cache.mjs";
|
|
6
6
|
|
|
7
|
-
const leftSpaceRe = /^\s(?:[^`]|$)/;
|
|
8
|
-
const rightSpaceRe = /[^`]\s$/;
|
|
9
|
-
const trimCodeText = (text, start, end) => {
|
|
10
|
-
text = text.replace(/^\s+$/, "");
|
|
11
|
-
if (start) {
|
|
12
|
-
text = text.replace(/^\s+?(\s`|\S)/, "$1");
|
|
13
|
-
}
|
|
14
|
-
if (end) {
|
|
15
|
-
text = text.replace(/(`\s|\S)\s+$/, "$1");
|
|
16
|
-
}
|
|
17
|
-
return text;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
7
|
/** @type {import("markdownlint").Rule} */
|
|
21
8
|
export default {
|
|
22
9
|
"names": [ "MD038", "no-space-in-code" ],
|
|
@@ -26,65 +13,59 @@ export default {
|
|
|
26
13
|
"function": function MD038(params, onError) {
|
|
27
14
|
const codeTexts = filterByTypesCached([ "codeText" ]);
|
|
28
15
|
for (const codeText of codeTexts) {
|
|
29
|
-
const sequences = getDescendantsByType(codeText, [ "codeTextSequence" ]);
|
|
30
|
-
const startSequence = sequences[0];
|
|
31
|
-
const endSequence = sequences[sequences.length - 1];
|
|
32
16
|
const datas = getDescendantsByType(codeText, [ "codeTextData" ]);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
fixInfo
|
|
86
|
-
);
|
|
87
|
-
}
|
|
17
|
+
if (datas.length > 0) {
|
|
18
|
+
const paddings = getDescendantsByType(codeText, [ "codeTextPadding" ]);
|
|
19
|
+
// Check for extra space at start of code
|
|
20
|
+
const startPadding = paddings[0];
|
|
21
|
+
const startData = datas[0];
|
|
22
|
+
const startMatch = /^(\s+)(\S)/.exec(startData.text) || [ null, "", "" ];
|
|
23
|
+
const startBacktick = (startMatch[2] === "`");
|
|
24
|
+
const startCount = startMatch[1].length - ((startBacktick && !startPadding) ? 1 : 0);
|
|
25
|
+
const startSpaces = startCount > 0;
|
|
26
|
+
// Check for extra space at end of code
|
|
27
|
+
const endPadding = paddings[paddings.length - 1];
|
|
28
|
+
const endData = datas[datas.length - 1];
|
|
29
|
+
const endMatch = /(\S)(\s+)$/.exec(endData.text) || [ null, "", "" ];
|
|
30
|
+
const endBacktick = (endMatch[1] === "`");
|
|
31
|
+
const endCount = endMatch[2].length - ((endBacktick && !endPadding) ? 1 : 0);
|
|
32
|
+
const endSpaces = endCount > 0;
|
|
33
|
+
// Check if safe to remove 1-space padding
|
|
34
|
+
const removePadding = startSpaces && endSpaces && startPadding && endPadding && !startBacktick && !endBacktick;
|
|
35
|
+
const context = codeText.text;
|
|
36
|
+
// If extra space at start, report violation
|
|
37
|
+
if (startSpaces) {
|
|
38
|
+
const startColumn = (removePadding ? startPadding : startData).startColumn;
|
|
39
|
+
const length = startCount + (removePadding ? startPadding.text.length : 0);
|
|
40
|
+
addErrorContext(
|
|
41
|
+
onError,
|
|
42
|
+
startData.startLine,
|
|
43
|
+
context,
|
|
44
|
+
true,
|
|
45
|
+
false,
|
|
46
|
+
[ startColumn, length ],
|
|
47
|
+
{
|
|
48
|
+
"editColumn": startColumn,
|
|
49
|
+
"deleteCount": length
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
// If extra space at end, report violation
|
|
54
|
+
if (endSpaces) {
|
|
55
|
+
const endColumn = (removePadding ? endPadding : endData).endColumn;
|
|
56
|
+
const length = endCount + (removePadding ? endPadding.text.length : 0);
|
|
57
|
+
addErrorContext(
|
|
58
|
+
onError,
|
|
59
|
+
endData.endLine,
|
|
60
|
+
context,
|
|
61
|
+
false,
|
|
62
|
+
true,
|
|
63
|
+
[ endColumn - length, length ],
|
|
64
|
+
{
|
|
65
|
+
"editColumn": endColumn - length,
|
|
66
|
+
"deleteCount": length
|
|
67
|
+
}
|
|
68
|
+
);
|
|
88
69
|
}
|
|
89
70
|
}
|
|
90
71
|
}
|