markdownlint 0.33.0 → 0.35.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 +19 -0
- package/CONTRIBUTING.md +4 -3
- package/README.md +25 -10
- package/demo/markdownlint-browser.js +3286 -2119
- package/doc/CustomRules.md +25 -13
- package/doc/Rules.md +106 -7
- package/doc/md013.md +8 -7
- package/doc/md034.md +5 -0
- package/doc/md044.md +10 -0
- package/doc/md049.md +3 -0
- package/doc/md050.md +3 -0
- package/doc/md051.md +26 -0
- package/doc/md058.md +48 -0
- package/helpers/README.md +3 -27
- package/helpers/helpers.js +60 -292
- package/helpers/micromark.cjs +153 -36
- package/helpers/package.json +2 -2
- package/lib/cache.js +62 -13
- package/lib/configuration-strict.d.ts +1185 -0
- package/lib/configuration.d.ts +3 -1173
- package/lib/constants.js +3 -2
- package/lib/markdownlint.d.ts +143 -61
- package/lib/markdownlint.js +151 -54
- package/lib/md001.js +17 -8
- package/lib/md003.js +16 -8
- package/lib/md004.js +57 -47
- package/lib/md005.js +7 -8
- package/lib/md007.js +13 -12
- package/lib/md009.js +52 -43
- package/lib/md010.js +50 -32
- package/lib/md011.js +18 -7
- package/lib/md012.js +19 -8
- package/lib/md013.js +46 -37
- package/lib/md014.js +37 -36
- package/lib/md018.js +20 -8
- package/lib/md019-md021.js +80 -0
- package/lib/md020.js +15 -6
- package/lib/md022.js +10 -12
- package/lib/md023.js +24 -22
- package/lib/md024.js +14 -8
- package/lib/md025.js +17 -9
- package/lib/md026.js +5 -6
- package/lib/md027.js +24 -43
- package/lib/md028.js +26 -14
- package/lib/md029.js +42 -33
- package/lib/md030.js +7 -8
- package/lib/md031.js +45 -22
- package/lib/md032.js +18 -30
- package/lib/md033.js +6 -4
- package/lib/md034.js +30 -9
- package/lib/md035.js +5 -3
- package/lib/md036.js +34 -39
- package/lib/md037.js +3 -0
- package/lib/md038.js +6 -5
- package/lib/md039.js +68 -52
- package/lib/md040.js +21 -21
- package/lib/md041.js +21 -26
- package/lib/md042.js +50 -36
- package/lib/md043.js +22 -13
- package/lib/md044.js +5 -2
- package/lib/md045.js +6 -4
- package/lib/md046.js +9 -8
- package/lib/md047.js +5 -2
- package/lib/md048.js +22 -13
- package/lib/md049-md050.js +19 -5
- package/lib/md051.js +18 -20
- package/lib/md052.js +5 -2
- package/lib/md053.js +5 -2
- package/lib/md054.js +12 -12
- package/lib/md055.js +10 -3
- package/lib/md056.js +18 -6
- package/lib/md058.js +43 -0
- package/lib/rules.js +11 -4
- package/package.json +22 -25
- package/schema/.markdownlint.jsonc +54 -51
- package/schema/.markdownlint.yaml +53 -50
- package/schema/ValidatingConfiguration.md +6 -8
- package/schema/markdownlint-config-schema-strict.json +1819 -0
- package/schema/markdownlint-config-schema.json +115 -105
- package/style/prettier.json +1 -0
- package/lib/md019.js +0 -39
- package/lib/md021.js +0 -62
package/lib/md013.js
CHANGED
|
@@ -2,30 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorDetailIf
|
|
6
|
-
|
|
7
|
-
const {
|
|
5
|
+
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
+
const { getReferenceLinkImageData } = require("./cache");
|
|
7
|
+
const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark.cjs");
|
|
8
|
+
const { filterByTypesCached } = require("./cache");
|
|
8
9
|
|
|
9
10
|
const longLineRePrefix = "^.{";
|
|
10
11
|
const longLineRePostfixRelaxed = "}.*\\s.*$";
|
|
11
12
|
const longLineRePostfixStrict = "}.+$";
|
|
12
|
-
const linkOrImageOnlyLineRe = /^[es]*(?:lT?L|I)[ES]*$/;
|
|
13
13
|
const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;
|
|
14
|
-
const tokenTypeMap = {
|
|
15
|
-
"em_open": "e",
|
|
16
|
-
"em_close": "E",
|
|
17
|
-
"image": "I",
|
|
18
|
-
"link_open": "l",
|
|
19
|
-
"link_close": "L",
|
|
20
|
-
"strong_open": "s",
|
|
21
|
-
"strong_close": "S",
|
|
22
|
-
"text": "T"
|
|
23
|
-
};
|
|
24
14
|
|
|
15
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
16
|
+
/** @type import("./markdownlint").Rule */
|
|
25
17
|
module.exports = {
|
|
26
18
|
"names": [ "MD013", "line-length" ],
|
|
27
19
|
"description": "Line length",
|
|
28
20
|
"tags": [ "line_length" ],
|
|
21
|
+
"parser": "micromark",
|
|
29
22
|
"function": function MD013(params, onError) {
|
|
30
23
|
const lineLength = Number(params.config.line_length || 80);
|
|
31
24
|
const headingLineLength =
|
|
@@ -48,26 +41,41 @@ module.exports = {
|
|
|
48
41
|
const includeTables = (tables === undefined) ? true : !!tables;
|
|
49
42
|
const headings = params.config.headings;
|
|
50
43
|
const includeHeadings = (headings === undefined) ? true : !!headings;
|
|
51
|
-
const headingLineNumbers =
|
|
52
|
-
|
|
53
|
-
headingLineNumbers.
|
|
54
|
-
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
const headingLineNumbers = new Set();
|
|
45
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
46
|
+
addRangeToSet(headingLineNumbers, heading.startLine, heading.endLine);
|
|
47
|
+
}
|
|
48
|
+
const codeBlockLineNumbers = new Set();
|
|
49
|
+
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
50
|
+
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
51
|
+
}
|
|
52
|
+
const tableLineNumbers = new Set();
|
|
53
|
+
for (const table of filterByTypesCached([ "table" ])) {
|
|
54
|
+
addRangeToSet(tableLineNumbers, table.startLine, table.endLine);
|
|
55
|
+
}
|
|
56
|
+
const linkLineNumbers = new Set();
|
|
57
|
+
for (const link of filterByTypesCached([ "autolink", "image", "link", "literalAutolink" ])) {
|
|
58
|
+
addRangeToSet(linkLineNumbers, link.startLine, link.endLine);
|
|
59
|
+
}
|
|
60
|
+
const paragraphDataLineNumbers = new Set();
|
|
61
|
+
for (const paragraph of filterByTypesCached([ "paragraph" ])) {
|
|
62
|
+
for (const data of getDescendantsByType(paragraph, [ "data" ])) {
|
|
63
|
+
addRangeToSet(paragraphDataLineNumbers, data.startLine, data.endLine);
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
}
|
|
66
|
+
const linkOnlyLineNumbers = new Set();
|
|
67
|
+
for (const lineNumber of linkLineNumbers) {
|
|
68
|
+
if (!paragraphDataLineNumbers.has(lineNumber)) {
|
|
69
|
+
linkOnlyLineNumbers.add(lineNumber);
|
|
65
70
|
}
|
|
66
|
-
}
|
|
67
|
-
const
|
|
68
|
-
|
|
71
|
+
}
|
|
72
|
+
const definitionLineIndices = new Set(getReferenceLinkImageData().definitionLineIndices);
|
|
73
|
+
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
|
74
|
+
const line = params.lines[lineIndex];
|
|
69
75
|
const lineNumber = lineIndex + 1;
|
|
70
|
-
const isHeading =
|
|
76
|
+
const isHeading = headingLineNumbers.has(lineNumber);
|
|
77
|
+
const inCode = codeBlockLineNumbers.has(lineNumber);
|
|
78
|
+
const inTable = tableLineNumbers.has(lineNumber);
|
|
71
79
|
const length = inCode ?
|
|
72
80
|
codeLineLength :
|
|
73
81
|
(isHeading ? headingLineLength : lineLength);
|
|
@@ -77,20 +85,21 @@ module.exports = {
|
|
|
77
85
|
if ((includeCodeBlocks || !inCode) &&
|
|
78
86
|
(includeTables || !inTable) &&
|
|
79
87
|
(includeHeadings || !isHeading) &&
|
|
80
|
-
!
|
|
88
|
+
!definitionLineIndices.has(lineIndex) &&
|
|
81
89
|
(strict ||
|
|
82
90
|
(!(stern && sternModeRe.test(line)) &&
|
|
83
|
-
!
|
|
91
|
+
!linkOnlyLineNumbers.has(lineNumber))) &&
|
|
84
92
|
lengthRe.test(line)) {
|
|
85
93
|
addErrorDetailIf(
|
|
86
94
|
onError,
|
|
87
95
|
lineNumber,
|
|
88
96
|
length,
|
|
89
97
|
line.length,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[ length + 1, line.length - length ]
|
|
98
|
+
undefined,
|
|
99
|
+
undefined,
|
|
100
|
+
[ length + 1, line.length - length ]
|
|
101
|
+
);
|
|
93
102
|
}
|
|
94
|
-
}
|
|
103
|
+
}
|
|
95
104
|
}
|
|
96
105
|
};
|
package/lib/md014.js
CHANGED
|
@@ -2,52 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
6
8
|
|
|
7
9
|
const dollarCommandRe = /^(\s*)(\$\s+)/;
|
|
8
10
|
|
|
11
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
12
|
+
/** @type import("./markdownlint").Rule */
|
|
9
13
|
module.exports = {
|
|
10
14
|
"names": [ "MD014", "commands-show-output" ],
|
|
11
15
|
"description": "Dollar signs used before commands without showing output",
|
|
12
16
|
"tags": [ "code" ],
|
|
17
|
+
"parser": "micromark",
|
|
13
18
|
"function": function MD014(params, onError) {
|
|
14
|
-
for (const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
20
|
+
const codeFlowValues = filterByTypes(
|
|
21
|
+
codeBlock.children,
|
|
22
|
+
[ "codeFlowValue" ]
|
|
23
|
+
);
|
|
24
|
+
const dollarMatches = codeFlowValues.
|
|
25
|
+
map((codeFlowValue) => ({
|
|
26
|
+
"result": codeFlowValue.text.match(dollarCommandRe),
|
|
27
|
+
"startColumn": codeFlowValue.startColumn,
|
|
28
|
+
"startLine": codeFlowValue.startLine,
|
|
29
|
+
"text": codeFlowValue.text
|
|
30
|
+
})).
|
|
31
|
+
filter((dollarMatch) => dollarMatch.result);
|
|
32
|
+
if (dollarMatches.length === codeFlowValues.length) {
|
|
33
|
+
for (const dollarMatch of dollarMatches) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const column = dollarMatch.startColumn + dollarMatch.result[1].length;
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const length = dollarMatch.result[2].length;
|
|
38
|
+
addErrorContext(
|
|
39
|
+
onError,
|
|
40
|
+
dollarMatch.startLine,
|
|
41
|
+
dollarMatch.text,
|
|
42
|
+
undefined,
|
|
43
|
+
undefined,
|
|
44
|
+
[ column, length ],
|
|
45
|
+
{
|
|
46
|
+
"editColumn": column,
|
|
47
|
+
"deleteCount": length
|
|
30
48
|
}
|
|
31
|
-
|
|
49
|
+
);
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
for (const instance of dollarInstances) {
|
|
35
|
-
const [ i, lineTrim, column, length ] = instance;
|
|
36
|
-
addErrorContext(
|
|
37
|
-
onError,
|
|
38
|
-
i + 1,
|
|
39
|
-
lineTrim,
|
|
40
|
-
null,
|
|
41
|
-
null,
|
|
42
|
-
[ column, length ],
|
|
43
|
-
{
|
|
44
|
-
"editColumn": column,
|
|
45
|
-
"deleteCount": length
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
+
}
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
};
|
package/lib/md018.js
CHANGED
|
@@ -2,26 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext
|
|
6
|
-
const {
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
7
8
|
|
|
9
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
10
|
+
/** @type import("./markdownlint").Rule */
|
|
8
11
|
module.exports = {
|
|
9
12
|
"names": [ "MD018", "no-missing-space-atx" ],
|
|
10
13
|
"description": "No space after hash on atx style heading",
|
|
11
14
|
"tags": [ "headings", "atx", "spaces" ],
|
|
15
|
+
"parser": "micromark",
|
|
12
16
|
"function": function MD018(params, onError) {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
const { lines } = params;
|
|
18
|
+
const ignoreBlockLineNumbers = new Set();
|
|
19
|
+
for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "htmlFlow" ])) {
|
|
20
|
+
addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
|
|
21
|
+
}
|
|
22
|
+
for (const [ lineIndex, line ] of lines.entries()) {
|
|
23
|
+
if (
|
|
24
|
+
!ignoreBlockLineNumbers.has(lineIndex + 1) &&
|
|
15
25
|
/^#+[^# \t]/.test(line) &&
|
|
16
26
|
!/#\s*$/.test(line) &&
|
|
17
|
-
!line.startsWith("#️⃣")
|
|
27
|
+
!line.startsWith("#️⃣")
|
|
28
|
+
) {
|
|
29
|
+
// @ts-ignore
|
|
18
30
|
const hashCount = /^#+/.exec(line)[0].length;
|
|
19
31
|
addErrorContext(
|
|
20
32
|
onError,
|
|
21
33
|
lineIndex + 1,
|
|
22
34
|
line.trim(),
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
undefined,
|
|
36
|
+
undefined,
|
|
25
37
|
[ 1, hashCount + 1 ],
|
|
26
38
|
{
|
|
27
39
|
"editColumn": hashCount + 1,
|
|
@@ -29,6 +41,6 @@ module.exports = {
|
|
|
29
41
|
}
|
|
30
42
|
);
|
|
31
43
|
}
|
|
32
|
-
}
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
46
|
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext } = require("../helpers/helpers");
|
|
6
|
+
const { getHeadingStyle } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Validate heading sequence and whitespace length at start or end.
|
|
11
|
+
*
|
|
12
|
+
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
|
|
13
|
+
* @param {import("./markdownlint").MicromarkToken} heading ATX heading token.
|
|
14
|
+
* @param {number} delta Direction to scan.
|
|
15
|
+
* @returns {void}
|
|
16
|
+
*/
|
|
17
|
+
function validateHeadingSpaces(onError, heading, delta) {
|
|
18
|
+
const { children, startLine, text } = heading;
|
|
19
|
+
let index = (delta > 0) ? 0 : (children.length - 1);
|
|
20
|
+
while (
|
|
21
|
+
children[index] &&
|
|
22
|
+
(children[index].type !== "atxHeadingSequence")
|
|
23
|
+
) {
|
|
24
|
+
index += delta;
|
|
25
|
+
}
|
|
26
|
+
const headingSequence = children[index];
|
|
27
|
+
const whitespace = children[index + delta];
|
|
28
|
+
if (
|
|
29
|
+
(headingSequence?.type === "atxHeadingSequence") &&
|
|
30
|
+
(whitespace?.type === "whitespace") &&
|
|
31
|
+
(whitespace.text.length > 1)
|
|
32
|
+
) {
|
|
33
|
+
const column = whitespace.startColumn + 1;
|
|
34
|
+
const length = whitespace.endColumn - column;
|
|
35
|
+
addErrorContext(
|
|
36
|
+
onError,
|
|
37
|
+
startLine,
|
|
38
|
+
text.trim(),
|
|
39
|
+
delta > 0,
|
|
40
|
+
delta < 0,
|
|
41
|
+
[ column, length ],
|
|
42
|
+
{
|
|
43
|
+
"editColumn": column,
|
|
44
|
+
"deleteCount": length
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
51
|
+
/** @type import("./markdownlint").Rule[] */
|
|
52
|
+
module.exports = [
|
|
53
|
+
{
|
|
54
|
+
"names": [ "MD019", "no-multiple-space-atx" ],
|
|
55
|
+
"description": "Multiple spaces after hash on atx style heading",
|
|
56
|
+
"tags": [ "headings", "atx", "spaces" ],
|
|
57
|
+
"parser": "micromark",
|
|
58
|
+
"function": function MD019(params, onError) {
|
|
59
|
+
const atxHeadings = filterByTypesCached([ "atxHeading" ])
|
|
60
|
+
.filter((heading) => getHeadingStyle(heading) === "atx");
|
|
61
|
+
for (const atxHeading of atxHeadings) {
|
|
62
|
+
validateHeadingSpaces(onError, atxHeading, 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"names": [ "MD021", "no-multiple-space-closed-atx" ],
|
|
68
|
+
"description": "Multiple spaces inside hashes on closed atx style heading",
|
|
69
|
+
"tags": [ "headings", "atx_closed", "spaces" ],
|
|
70
|
+
"parser": "micromark",
|
|
71
|
+
"function": function MD021(params, onError) {
|
|
72
|
+
const atxClosedHeadings = filterByTypesCached([ "atxHeading" ])
|
|
73
|
+
.filter((heading) => getHeadingStyle(heading) === "atx_closed");
|
|
74
|
+
for (const atxClosedHeading of atxClosedHeadings) {
|
|
75
|
+
validateHeadingSpaces(onError, atxClosedHeading, 1);
|
|
76
|
+
validateHeadingSpaces(onError, atxClosedHeading, -1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
];
|
package/lib/md020.js
CHANGED
|
@@ -2,16 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext
|
|
6
|
-
const {
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
7
8
|
|
|
9
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
10
|
+
/** @type import("./markdownlint").Rule */
|
|
8
11
|
module.exports = {
|
|
9
12
|
"names": [ "MD020", "no-missing-space-closed-atx" ],
|
|
10
13
|
"description": "No space inside hashes on closed atx style heading",
|
|
11
14
|
"tags": [ "headings", "atx_closed", "spaces" ],
|
|
15
|
+
"parser": "micromark",
|
|
12
16
|
"function": function MD020(params, onError) {
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
const { lines } = params;
|
|
18
|
+
const ignoreBlockLineNumbers = new Set();
|
|
19
|
+
for (const ignoreBlock of filterByTypesCached([ "codeFenced", "codeIndented", "htmlFlow" ])) {
|
|
20
|
+
addRangeToSet(ignoreBlockLineNumbers, ignoreBlock.startLine, ignoreBlock.endLine);
|
|
21
|
+
}
|
|
22
|
+
for (const [ lineIndex, line ] of lines.entries()) {
|
|
23
|
+
if (!ignoreBlockLineNumbers.has(lineIndex + 1)) {
|
|
15
24
|
const match =
|
|
16
25
|
/^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
|
|
17
26
|
if (match) {
|
|
@@ -28,7 +37,7 @@ module.exports = {
|
|
|
28
37
|
const leftHashLength = leftHash.length;
|
|
29
38
|
const rightHashLength = rightHash.length;
|
|
30
39
|
const left = !leftSpaceLength;
|
|
31
|
-
const right = !rightSpaceLength || rightEscape;
|
|
40
|
+
const right = !rightSpaceLength || !!rightEscape;
|
|
32
41
|
const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : "";
|
|
33
42
|
if (left || right) {
|
|
34
43
|
const range = left ?
|
|
@@ -57,6 +66,6 @@ module.exports = {
|
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
|
-
}
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
};
|
package/lib/md022.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
require("../helpers/micromark.cjs");
|
|
5
|
+
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } = require("../helpers");
|
|
6
|
+
const { getHeadingLevel } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
9
8
|
|
|
10
9
|
const defaultLines = 1;
|
|
11
10
|
|
|
@@ -31,19 +30,18 @@ const getBlockQuote = (str, count) => (
|
|
|
31
30
|
.repeat(count)
|
|
32
31
|
);
|
|
33
32
|
|
|
33
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
34
|
+
/** @type import("./markdownlint").Rule */
|
|
34
35
|
module.exports = {
|
|
35
36
|
"names": [ "MD022", "blanks-around-headings" ],
|
|
36
37
|
"description": "Headings should be surrounded by blank lines",
|
|
37
38
|
"tags": [ "headings", "blank_lines" ],
|
|
39
|
+
"parser": "micromark",
|
|
38
40
|
"function": function MD022(params, onError) {
|
|
39
41
|
const getLinesAbove = getLinesFunction(params.config.lines_above);
|
|
40
42
|
const getLinesBelow = getLinesFunction(params.config.lines_below);
|
|
41
|
-
const { lines
|
|
42
|
-
const
|
|
43
|
-
parsers.micromark.tokens,
|
|
44
|
-
[ "atxHeading", "setextHeading" ]
|
|
45
|
-
).filter((heading) => !inHtmlFlow(heading));
|
|
46
|
-
for (const heading of headings) {
|
|
43
|
+
const { lines } = params;
|
|
44
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
47
45
|
const { startLine, endLine } = heading;
|
|
48
46
|
const line = lines[startLine - 1].trim();
|
|
49
47
|
|
|
@@ -65,7 +63,7 @@ module.exports = {
|
|
|
65
63
|
actualAbove,
|
|
66
64
|
"Above",
|
|
67
65
|
line,
|
|
68
|
-
|
|
66
|
+
undefined,
|
|
69
67
|
{
|
|
70
68
|
"insertText": getBlockQuote(
|
|
71
69
|
lines[startLine - 2],
|
|
@@ -93,7 +91,7 @@ module.exports = {
|
|
|
93
91
|
actualBelow,
|
|
94
92
|
"Below",
|
|
95
93
|
line,
|
|
96
|
-
|
|
94
|
+
undefined,
|
|
97
95
|
{
|
|
98
96
|
"lineNumber": endLine + 1,
|
|
99
97
|
"insertText": getBlockQuote(
|
package/lib/md023.js
CHANGED
|
@@ -2,37 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext
|
|
6
|
-
|
|
7
|
-
const spaceBeforeHeadingRe = /^(\s+|[>\s]+\s\s)[^>\s]/;
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { filterByTypesCached } = require("./cache");
|
|
8
7
|
|
|
8
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
9
|
+
/** @type import("./markdownlint").Rule */
|
|
9
10
|
module.exports = {
|
|
10
11
|
"names": [ "MD023", "heading-start-left" ],
|
|
11
12
|
"description": "Headings must start at the beginning of the line",
|
|
12
13
|
"tags": [ "headings", "spaces" ],
|
|
14
|
+
"parser": "micromark",
|
|
13
15
|
"function": function MD023(params, onError) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
const headings = filterByTypesCached([ "atxHeading", "linePrefix", "setextHeading" ]);
|
|
17
|
+
for (let i = 0; i < headings.length - 1; i++) {
|
|
18
|
+
if (
|
|
19
|
+
(headings[i].type === "linePrefix") &&
|
|
20
|
+
(headings[i + 1].type !== "linePrefix") &&
|
|
21
|
+
(headings[i].startLine === headings[i + 1].startLine)
|
|
22
|
+
) {
|
|
23
|
+
const { endColumn, startColumn, startLine } = headings[i];
|
|
24
|
+
const length = endColumn - startColumn;
|
|
24
25
|
addErrorContext(
|
|
25
26
|
onError,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[
|
|
27
|
+
startLine,
|
|
28
|
+
params.lines[startLine - 1],
|
|
29
|
+
true,
|
|
30
|
+
false,
|
|
31
|
+
[ startColumn, length ],
|
|
31
32
|
{
|
|
32
|
-
"editColumn":
|
|
33
|
-
"deleteCount":
|
|
34
|
-
}
|
|
33
|
+
"editColumn": startColumn,
|
|
34
|
+
"deleteCount": length
|
|
35
|
+
}
|
|
36
|
+
);
|
|
35
37
|
}
|
|
36
|
-
}
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
40
|
};
|
package/lib/md024.js
CHANGED
|
@@ -2,20 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
6
8
|
|
|
9
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
10
|
+
/** @type import("./markdownlint").Rule */
|
|
7
11
|
module.exports = {
|
|
8
12
|
"names": [ "MD024", "no-duplicate-heading" ],
|
|
9
13
|
"description": "Multiple headings with the same content",
|
|
10
14
|
"tags": [ "headings" ],
|
|
15
|
+
"parser": "micromark",
|
|
11
16
|
"function": function MD024(params, onError) {
|
|
12
17
|
const siblingsOnly = !!params.config.siblings_only || false;
|
|
13
18
|
const knownContents = [ null, [] ];
|
|
14
19
|
let lastLevel = 1;
|
|
15
20
|
let knownContent = knownContents[lastLevel];
|
|
16
|
-
|
|
21
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
22
|
+
const headingText = getHeadingText(heading);
|
|
17
23
|
if (siblingsOnly) {
|
|
18
|
-
const newLevel = heading
|
|
24
|
+
const newLevel = getHeadingLevel(heading);
|
|
19
25
|
while (lastLevel < newLevel) {
|
|
20
26
|
lastLevel++;
|
|
21
27
|
knownContents[lastLevel] = [];
|
|
@@ -27,16 +33,16 @@ module.exports = {
|
|
|
27
33
|
knownContent = knownContents[newLevel];
|
|
28
34
|
}
|
|
29
35
|
// @ts-ignore
|
|
30
|
-
if (knownContent.includes(
|
|
36
|
+
if (knownContent.includes(headingText)) {
|
|
31
37
|
addErrorContext(
|
|
32
38
|
onError,
|
|
33
|
-
heading.
|
|
34
|
-
|
|
39
|
+
heading.startLine,
|
|
40
|
+
headingText.trim()
|
|
35
41
|
);
|
|
36
42
|
} else {
|
|
37
43
|
// @ts-ignore
|
|
38
|
-
knownContent.push(
|
|
44
|
+
knownContent.push(headingText);
|
|
39
45
|
}
|
|
40
|
-
}
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
};
|
package/lib/md025.js
CHANGED
|
@@ -2,31 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorContext,
|
|
6
|
-
|
|
5
|
+
const { addErrorContext, frontMatterHasTitle } = require("../helpers");
|
|
6
|
+
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
7
8
|
|
|
9
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
10
|
+
/** @type import("./markdownlint").Rule */
|
|
8
11
|
module.exports = {
|
|
9
12
|
"names": [ "MD025", "single-title", "single-h1" ],
|
|
10
13
|
"description": "Multiple top-level headings in the same document",
|
|
11
14
|
"tags": [ "headings" ],
|
|
15
|
+
"parser": "micromark",
|
|
12
16
|
"function": function MD025(params, onError) {
|
|
13
17
|
const level = Number(params.config.level || 1);
|
|
14
|
-
const tag = "h" + level;
|
|
15
18
|
const foundFrontMatterTitle =
|
|
16
19
|
frontMatterHasTitle(
|
|
17
20
|
params.frontMatterLines,
|
|
18
21
|
params.config.front_matter_title
|
|
19
22
|
);
|
|
20
23
|
let hasTopLevelHeading = false;
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
25
|
+
const headingLevel = getHeadingLevel(heading);
|
|
26
|
+
if (headingLevel === level) {
|
|
23
27
|
if (hasTopLevelHeading || foundFrontMatterTitle) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const headingText = getHeadingText(heading);
|
|
29
|
+
addErrorContext(
|
|
30
|
+
onError,
|
|
31
|
+
heading.startLine,
|
|
32
|
+
headingText
|
|
33
|
+
);
|
|
34
|
+
} else if (heading.startLine === 1) {
|
|
27
35
|
hasTopLevelHeading = true;
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
|
-
}
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
};
|
package/lib/md026.js
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
|
|
6
6
|
endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers");
|
|
7
|
-
const {
|
|
8
|
-
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
9
8
|
|
|
9
|
+
// eslint-disable-next-line jsdoc/valid-types
|
|
10
|
+
/** @type import("./markdownlint").Rule */
|
|
10
11
|
module.exports = {
|
|
11
12
|
"names": [ "MD026", "no-trailing-punctuation" ],
|
|
12
13
|
"description": "Trailing punctuation in heading",
|
|
13
14
|
"tags": [ "headings" ],
|
|
15
|
+
"parser": "micromark",
|
|
14
16
|
"function": function MD026(params, onError) {
|
|
15
17
|
let punctuation = params.config.punctuation;
|
|
16
18
|
punctuation = String(
|
|
@@ -18,10 +20,7 @@ module.exports = {
|
|
|
18
20
|
);
|
|
19
21
|
const trailingPunctuationRe =
|
|
20
22
|
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
|
|
21
|
-
const headings =
|
|
22
|
-
params.parsers.micromark.tokens,
|
|
23
|
-
[ "atxHeadingText", "setextHeadingText" ]
|
|
24
|
-
);
|
|
23
|
+
const headings = filterByTypesCached([ "atxHeadingText", "setextHeadingText" ]);
|
|
25
24
|
for (const heading of headings) {
|
|
26
25
|
const { endColumn, endLine, text } = heading;
|
|
27
26
|
const match = trailingPunctuationRe.exec(text);
|