markdownlint 0.35.0 → 0.36.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.
- package/CHANGELOG.md +14 -0
- package/README.md +72 -35
- package/demo/markdownlint-browser.js +1259 -1215
- package/doc/CustomRules.md +55 -249
- package/doc/Rules.md +36 -29
- package/doc/md003.md +2 -2
- package/doc/md004.md +4 -3
- package/doc/md035.md +3 -8
- package/doc/md046.md +2 -2
- package/doc/md048.md +3 -2
- package/doc/md049.md +4 -3
- package/doc/md050.md +4 -4
- package/doc/md051.md +11 -3
- package/doc/md055.md +3 -2
- package/helpers/README.md +2 -19
- package/helpers/helpers.js +87 -347
- package/helpers/micromark-helpers.cjs +296 -0
- package/helpers/micromark-parse.cjs +313 -0
- package/helpers/package.json +5 -2
- package/helpers/shared.js +6 -0
- package/helpers/test.cjs +28 -0
- package/lib/cache.js +3 -3
- package/lib/configuration-strict.d.ts +120 -106
- package/lib/constants.js +1 -1
- package/lib/markdownit.cjs +172 -0
- package/lib/markdownlint.d.ts +41 -3
- package/lib/markdownlint.js +153 -115
- package/lib/md001.js +1 -1
- package/lib/md003.js +1 -1
- package/lib/md004.js +3 -3
- package/lib/md007.js +3 -3
- package/lib/md009.js +1 -1
- package/lib/md010.js +18 -14
- package/lib/md011.js +24 -23
- package/lib/md012.js +1 -1
- package/lib/md013.js +1 -1
- package/lib/md014.js +5 -9
- package/lib/md018.js +1 -1
- package/lib/md019-md021.js +1 -1
- package/lib/md020.js +2 -2
- package/lib/md022.js +9 -15
- package/lib/md024.js +1 -1
- package/lib/md025.js +1 -1
- package/lib/md027.js +2 -2
- package/lib/md029.js +3 -3
- package/lib/md031.js +8 -6
- package/lib/md032.js +27 -15
- package/lib/md033.js +1 -1
- package/lib/md034.js +21 -29
- package/lib/md036.js +18 -24
- package/lib/md037.js +1 -1
- package/lib/md038.js +9 -14
- package/lib/md039.js +13 -15
- package/lib/md040.js +11 -13
- package/lib/md041.js +4 -4
- package/lib/md042.js +2 -6
- package/lib/md043.js +1 -1
- package/lib/md044.js +31 -28
- package/lib/md045.js +2 -2
- package/lib/md048.js +28 -17
- package/lib/md049-md050.js +20 -5
- package/lib/md051.js +16 -18
- package/lib/md053.js +5 -4
- package/lib/md054.js +11 -13
- package/lib/md055.js +39 -46
- package/lib/md056.js +31 -36
- package/lib/md058.js +29 -14
- package/package.json +14 -13
- package/schema/.markdownlint.jsonc +55 -52
- package/schema/.markdownlint.yaml +54 -52
- package/schema/markdownlint-config-schema-strict.json +132 -110
- package/schema/markdownlint-config-schema.json +132 -110
- package/helpers/micromark.cjs +0 -544
package/lib/md007.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
-
const {
|
|
6
|
+
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
|
@@ -35,11 +35,11 @@ module.exports = {
|
|
|
35
35
|
lastBlockQuotePrefix = token;
|
|
36
36
|
} else if (type === "listUnordered") {
|
|
37
37
|
let nesting = 0;
|
|
38
|
-
/** @type {import("../helpers/micromark.cjs").Token | null} */
|
|
38
|
+
/** @type {import("../helpers/micromark-helpers.cjs").Token | null} */
|
|
39
39
|
let current = token;
|
|
40
40
|
while (
|
|
41
41
|
// @ts-ignore
|
|
42
|
-
(current =
|
|
42
|
+
(current = getParentOfType(current, unorderedParentTypes))
|
|
43
43
|
) {
|
|
44
44
|
if (current.type === "listUnordered") {
|
|
45
45
|
nesting++;
|
package/lib/md009.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addError } = require("../helpers");
|
|
6
|
-
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md010.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addError,
|
|
6
|
-
const { getDescendantsByType
|
|
5
|
+
const { addError, hasOverlap } = require("../helpers");
|
|
6
|
+
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
const tabRe = /\t+/g;
|
|
@@ -26,9 +26,8 @@ module.exports = {
|
|
|
26
26
|
const spaceMultiplier = (spacesPerTab === undefined) ?
|
|
27
27
|
1 :
|
|
28
28
|
Math.max(0, Number(spacesPerTab));
|
|
29
|
-
const exclusions = [];
|
|
30
29
|
// eslint-disable-next-line jsdoc/valid-types
|
|
31
|
-
/** @type import("../helpers/micromark.cjs").TokenType[] */
|
|
30
|
+
/** @type import("../helpers/micromark-helpers.cjs").TokenType[] */
|
|
32
31
|
const exclusionTypes = [];
|
|
33
32
|
if (includeCode) {
|
|
34
33
|
if (ignoreCodeLanguages.size > 0) {
|
|
@@ -44,24 +43,29 @@ module.exports = {
|
|
|
44
43
|
}
|
|
45
44
|
return true;
|
|
46
45
|
});
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
const codeRanges = codeTokens.map((token) => {
|
|
47
|
+
const { type, startLine, startColumn, endLine, endColumn } = token;
|
|
48
|
+
const codeFenced = (type === "codeFenced");
|
|
49
|
+
return {
|
|
50
|
+
"startLine": startLine + (codeFenced ? 1 : 0),
|
|
51
|
+
"startColumn": codeFenced ? 0 : startColumn,
|
|
52
|
+
"endLine": endLine - (codeFenced ? 1 : 0),
|
|
53
|
+
"endColumn": codeFenced ? Number.MAX_SAFE_INTEGER : endColumn
|
|
54
|
+
};
|
|
55
|
+
});
|
|
55
56
|
for (let lineIndex = 0; lineIndex < params.lines.length; lineIndex++) {
|
|
56
57
|
const line = params.lines[lineIndex];
|
|
57
58
|
let match = null;
|
|
58
59
|
while ((match = tabRe.exec(line)) !== null) {
|
|
60
|
+
const lineNumber = lineIndex + 1;
|
|
59
61
|
const column = match.index + 1;
|
|
60
62
|
const length = match[0].length;
|
|
61
|
-
|
|
63
|
+
/** @type {import("../helpers").FileRange} */
|
|
64
|
+
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
|
|
65
|
+
if (!codeRanges.some((codeRange) => hasOverlap(codeRange, range))) {
|
|
62
66
|
addError(
|
|
63
67
|
onError,
|
|
64
|
-
|
|
68
|
+
lineNumber,
|
|
65
69
|
"Column: " + column,
|
|
66
70
|
undefined,
|
|
67
71
|
[ column, length ],
|
package/lib/md011.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addError,
|
|
6
|
-
const { addRangeToSet
|
|
5
|
+
const { addError, hasOverlap } = require("../helpers");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
const reversedLinkRe =
|
|
@@ -21,34 +21,35 @@ module.exports = {
|
|
|
21
21
|
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
22
22
|
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
for (const codeText of filterByTypesCached([ "codeText" ])) {
|
|
26
|
-
exclusions.push(...getExclusionsForToken(params.lines, codeText));
|
|
27
|
-
}
|
|
24
|
+
const codeTexts = filterByTypesCached([ "codeText" ]);
|
|
28
25
|
for (const [ lineIndex, line ] of params.lines.entries()) {
|
|
29
|
-
|
|
26
|
+
const lineNumber = lineIndex + 1;
|
|
27
|
+
if (!codeBlockLineNumbers.has(lineNumber)) {
|
|
30
28
|
let match = null;
|
|
31
29
|
while ((match = reversedLinkRe.exec(line)) !== null) {
|
|
32
30
|
const [ reversedLink, preChar, linkText, linkDestination ] = match;
|
|
33
|
-
const index = match.index + preChar.length;
|
|
34
|
-
const length = match[0].length - preChar.length;
|
|
35
31
|
if (
|
|
36
32
|
!linkText.endsWith("\\") &&
|
|
37
|
-
!linkDestination.endsWith("\\")
|
|
38
|
-
!withinAnyRange(exclusions, lineIndex + 1, index, length)
|
|
33
|
+
!linkDestination.endsWith("\\")
|
|
39
34
|
) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
const column = match.index + preChar.length + 1;
|
|
36
|
+
const length = match[0].length - preChar.length;
|
|
37
|
+
/** @type {import("../helpers").FileRange} */
|
|
38
|
+
const range = { "startLine": lineNumber, "startColumn": column, "endLine": lineNumber, "endColumn": column + length - 1 };
|
|
39
|
+
if (!codeTexts.some((codeText) => hasOverlap(codeText, range))) {
|
|
40
|
+
addError(
|
|
41
|
+
onError,
|
|
42
|
+
lineNumber,
|
|
43
|
+
reversedLink.slice(preChar.length),
|
|
44
|
+
undefined,
|
|
45
|
+
[ column, length ],
|
|
46
|
+
{
|
|
47
|
+
"editColumn": column,
|
|
48
|
+
"deleteCount": length,
|
|
49
|
+
"insertText": `[${linkText}](${linkDestination})`
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
package/lib/md012.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
-
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md013.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const { addErrorDetailIf } = require("../helpers");
|
|
6
6
|
const { getReferenceLinkImageData } = require("./cache");
|
|
7
|
-
const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark.cjs");
|
|
7
|
+
const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
8
8
|
const { filterByTypesCached } = require("./cache");
|
|
9
9
|
|
|
10
10
|
const longLineRePrefix = "^.{";
|
package/lib/md014.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers");
|
|
6
|
-
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
7
6
|
const { filterByTypesCached } = require("./cache");
|
|
8
7
|
|
|
9
8
|
const dollarCommandRe = /^(\s*)(\$\s+)/;
|
|
@@ -17,18 +16,15 @@ module.exports = {
|
|
|
17
16
|
"parser": "micromark",
|
|
18
17
|
"function": function MD014(params, onError) {
|
|
19
18
|
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
|
20
|
-
const codeFlowValues =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
);
|
|
24
|
-
const dollarMatches = codeFlowValues.
|
|
25
|
-
map((codeFlowValue) => ({
|
|
19
|
+
const codeFlowValues = codeBlock.children.filter((child) => child.type === "codeFlowValue");
|
|
20
|
+
const dollarMatches = codeFlowValues
|
|
21
|
+
.map((codeFlowValue) => ({
|
|
26
22
|
"result": codeFlowValue.text.match(dollarCommandRe),
|
|
27
23
|
"startColumn": codeFlowValue.startColumn,
|
|
28
24
|
"startLine": codeFlowValue.startLine,
|
|
29
25
|
"text": codeFlowValue.text
|
|
30
|
-
}))
|
|
31
|
-
filter((dollarMatch) => dollarMatch.result);
|
|
26
|
+
}))
|
|
27
|
+
.filter((dollarMatch) => dollarMatch.result);
|
|
32
28
|
if (dollarMatches.length === codeFlowValues.length) {
|
|
33
29
|
for (const dollarMatch of dollarMatches) {
|
|
34
30
|
// @ts-ignore
|
package/lib/md018.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers");
|
|
6
|
-
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md019-md021.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers/helpers");
|
|
6
|
-
const { getHeadingStyle } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { getHeadingStyle } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
/**
|
package/lib/md020.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers");
|
|
6
|
-
const { addRangeToSet } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
|
@@ -22,7 +22,7 @@ module.exports = {
|
|
|
22
22
|
for (const [ lineIndex, line ] of lines.entries()) {
|
|
23
23
|
if (!ignoreBlockLineNumbers.has(lineIndex + 1)) {
|
|
24
24
|
const match =
|
|
25
|
-
/^(#+)([ \t]*)([^#]*?[
|
|
25
|
+
/^(#+)([ \t]*)([^# \t\\]|[^# \t][^#]*?[^# \t\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
|
|
26
26
|
if (match) {
|
|
27
27
|
const [
|
|
28
28
|
,
|
package/lib/md022.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const { addErrorDetailIf,
|
|
6
|
-
const { getHeadingLevel } = require("../helpers/micromark.cjs");
|
|
5
|
+
const { addErrorDetailIf, isBlankLine } = require("../helpers");
|
|
6
|
+
const { getBlockQuotePrefixText, getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
const defaultLines = 1;
|
|
@@ -21,15 +21,6 @@ const getLinesFunction = (linesParam) => {
|
|
|
21
21
|
return () => lines;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const getBlockQuote = (str, count) => (
|
|
25
|
-
(str || "")
|
|
26
|
-
.match(blockquotePrefixRe)[0]
|
|
27
|
-
.trimEnd()
|
|
28
|
-
// eslint-disable-next-line unicorn/prefer-spread
|
|
29
|
-
.concat("\n")
|
|
30
|
-
.repeat(count)
|
|
31
|
-
);
|
|
32
|
-
|
|
33
24
|
// eslint-disable-next-line jsdoc/valid-types
|
|
34
25
|
/** @type import("./markdownlint").Rule */
|
|
35
26
|
module.exports = {
|
|
@@ -41,6 +32,7 @@ module.exports = {
|
|
|
41
32
|
const getLinesAbove = getLinesFunction(params.config.lines_above);
|
|
42
33
|
const getLinesBelow = getLinesFunction(params.config.lines_below);
|
|
43
34
|
const { lines } = params;
|
|
35
|
+
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
|
44
36
|
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
|
45
37
|
const { startLine, endLine } = heading;
|
|
46
38
|
const line = lines[startLine - 1].trim();
|
|
@@ -65,8 +57,9 @@ module.exports = {
|
|
|
65
57
|
line,
|
|
66
58
|
undefined,
|
|
67
59
|
{
|
|
68
|
-
"insertText":
|
|
69
|
-
|
|
60
|
+
"insertText": getBlockQuotePrefixText(
|
|
61
|
+
blockQuotePrefixes,
|
|
62
|
+
startLine - 1,
|
|
70
63
|
linesAbove - actualAbove
|
|
71
64
|
)
|
|
72
65
|
}
|
|
@@ -94,8 +87,9 @@ module.exports = {
|
|
|
94
87
|
undefined,
|
|
95
88
|
{
|
|
96
89
|
"lineNumber": endLine + 1,
|
|
97
|
-
"insertText":
|
|
98
|
-
|
|
90
|
+
"insertText": getBlockQuotePrefixText(
|
|
91
|
+
blockQuotePrefixes,
|
|
92
|
+
endLine + 1,
|
|
99
93
|
linesBelow - actualBelow
|
|
100
94
|
)
|
|
101
95
|
}
|
package/lib/md024.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers");
|
|
6
|
-
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md025.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext, frontMatterHasTitle } = require("../helpers");
|
|
6
|
-
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md027.js
CHANGED
|
@@ -8,9 +8,9 @@ const { filterByTypesCached } = require("./cache");
|
|
|
8
8
|
// eslint-disable-next-line jsdoc/valid-types
|
|
9
9
|
/** @type import("./markdownlint").Rule */
|
|
10
10
|
module.exports = {
|
|
11
|
-
"names": ["MD027", "no-multiple-space-blockquote"],
|
|
11
|
+
"names": [ "MD027", "no-multiple-space-blockquote" ],
|
|
12
12
|
"description": "Multiple spaces after blockquote symbol",
|
|
13
|
-
"tags": ["blockquote", "whitespace", "indentation"],
|
|
13
|
+
"tags": [ "blockquote", "whitespace", "indentation" ],
|
|
14
14
|
"parser": "micromark",
|
|
15
15
|
"function": function MD027(params, onError) {
|
|
16
16
|
for (const token of filterByTypesCached([ "linePrefix" ])) {
|
package/lib/md029.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
-
const { getDescendantsByType
|
|
6
|
+
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
const listStyleExamples = {
|
|
@@ -15,11 +15,11 @@ const listStyleExamples = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Gets the value of an ordered list item prefix token.
|
|
17
17
|
*
|
|
18
|
-
* @param {import("../helpers/micromark.cjs").Token} listItemPrefix List item prefix token.
|
|
18
|
+
* @param {import("../helpers/micromark-helpers.cjs").Token} listItemPrefix List item prefix token.
|
|
19
19
|
* @returns {number} List item value.
|
|
20
20
|
*/
|
|
21
21
|
function getOrderedListItemValue(listItemPrefix) {
|
|
22
|
-
return Number(
|
|
22
|
+
return Number(getDescendantsByType(listItemPrefix, [ "listItemValue" ])[0].text);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md031.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext, isBlankLine } = require("../helpers");
|
|
6
|
-
const {
|
|
6
|
+
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
const codeFencePrefixRe = /^(.*?)[`~]/;
|
|
@@ -23,10 +23,12 @@ const codeFencePrefixRe = /^(.*?)[`~]/;
|
|
|
23
23
|
function addError(onError, lines, lineNumber, top) {
|
|
24
24
|
const line = lines[lineNumber - 1];
|
|
25
25
|
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
|
|
26
|
-
const fixInfo = (prefix === undefined) ?
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const fixInfo = (prefix === undefined) ?
|
|
27
|
+
null :
|
|
28
|
+
{
|
|
29
|
+
"lineNumber": lineNumber + (top ? 0 : 1),
|
|
30
|
+
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
|
|
31
|
+
};
|
|
30
32
|
addErrorContext(
|
|
31
33
|
onError,
|
|
32
34
|
lineNumber,
|
|
@@ -50,7 +52,7 @@ module.exports = {
|
|
|
50
52
|
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
|
51
53
|
const { lines } = params;
|
|
52
54
|
for (const codeBlock of filterByTypesCached([ "codeFenced" ])) {
|
|
53
|
-
if (includeListItems || !(
|
|
55
|
+
if (includeListItems || !(getParentOfType(codeBlock, [ "listOrdered", "listUnordered" ]))) {
|
|
54
56
|
if (!isBlankLine(lines[codeBlock.startLine - 2])) {
|
|
55
57
|
addError(onError, lines, codeBlock.startLine, true);
|
|
56
58
|
}
|
package/lib/md032.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
const { filterByPredicate, nonContentTokens } = require("../helpers/micromark.cjs");
|
|
5
|
+
const { addErrorContext, isBlankLine } = require("../helpers");
|
|
6
|
+
const { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } = require("../helpers/micromark-helpers.cjs");
|
|
7
|
+
const { filterByTypesCached } = require("./cache");
|
|
7
8
|
|
|
8
9
|
const isList = (token) => (
|
|
9
10
|
(token.type === "listOrdered") || (token.type === "listUnordered")
|
|
@@ -18,6 +19,7 @@ module.exports = {
|
|
|
18
19
|
"parser": "micromark",
|
|
19
20
|
"function": function MD032(params, onError) {
|
|
20
21
|
const { lines, parsers } = params;
|
|
22
|
+
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
|
21
23
|
|
|
22
24
|
// For every top-level list...
|
|
23
25
|
const topLevelLists = filterByPredicate(
|
|
@@ -30,13 +32,18 @@ module.exports = {
|
|
|
30
32
|
for (const list of topLevelLists) {
|
|
31
33
|
|
|
32
34
|
// Look for a blank line above the list
|
|
33
|
-
const
|
|
34
|
-
if (!isBlankLine(lines[
|
|
35
|
-
|
|
35
|
+
const firstLineNumber = list.startLine;
|
|
36
|
+
if (!isBlankLine(lines[firstLineNumber - 2])) {
|
|
37
|
+
addErrorContext(
|
|
36
38
|
onError,
|
|
37
|
-
|
|
38
|
-
lines,
|
|
39
|
-
|
|
39
|
+
firstLineNumber,
|
|
40
|
+
lines[firstLineNumber - 1].trim(),
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
undefined,
|
|
44
|
+
{
|
|
45
|
+
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, firstLineNumber)
|
|
46
|
+
}
|
|
40
47
|
);
|
|
41
48
|
}
|
|
42
49
|
|
|
@@ -51,14 +58,19 @@ module.exports = {
|
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
// Look for a blank line below the list
|
|
54
|
-
const
|
|
55
|
-
if (!isBlankLine(lines[
|
|
56
|
-
|
|
61
|
+
const lastLineNumber = endLine;
|
|
62
|
+
if (!isBlankLine(lines[lastLineNumber])) {
|
|
63
|
+
addErrorContext(
|
|
57
64
|
onError,
|
|
58
|
-
|
|
59
|
-
lines,
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
lastLineNumber,
|
|
66
|
+
lines[lastLineNumber - 1].trim(),
|
|
67
|
+
undefined,
|
|
68
|
+
undefined,
|
|
69
|
+
undefined,
|
|
70
|
+
{
|
|
71
|
+
"lineNumber": lastLineNumber + 1,
|
|
72
|
+
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, lastLineNumber)
|
|
73
|
+
}
|
|
62
74
|
);
|
|
63
75
|
}
|
|
64
76
|
}
|
package/lib/md033.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addError, nextLinesRe } = require("../helpers");
|
|
6
|
-
const { getHtmlTagInfo } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line jsdoc/valid-types
|
package/lib/md034.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext } = require("../helpers");
|
|
6
|
-
const { filterByPredicate, getHtmlTagInfo, inHtmlFlow
|
|
7
|
-
const { filterByTypesCached } = require("./cache");
|
|
6
|
+
const { filterByPredicate, getHtmlTagInfo, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
|
|
8
7
|
|
|
9
8
|
// eslint-disable-next-line jsdoc/valid-types
|
|
10
9
|
/** @type import("./markdownlint").Rule */
|
|
@@ -21,8 +20,6 @@ module.exports = {
|
|
|
21
20
|
if ((token.type === "literalAutolink") && !inHtmlFlow(token)) {
|
|
22
21
|
// Detect and ignore https://github.com/micromark/micromark/issues/164
|
|
23
22
|
const siblings = token.parent?.children;
|
|
24
|
-
// Commented-out due to not being able to exercise in test/code coverage
|
|
25
|
-
// || micromarkTokens;
|
|
26
23
|
const index = siblings?.indexOf(token);
|
|
27
24
|
// @ts-ignore
|
|
28
25
|
const prev = siblings?.at(index - 1);
|
|
@@ -40,6 +37,7 @@ module.exports = {
|
|
|
40
37
|
return false;
|
|
41
38
|
},
|
|
42
39
|
(token) => {
|
|
40
|
+
// Ignore content of inline HTML tags
|
|
43
41
|
const { children } = token;
|
|
44
42
|
const result = [];
|
|
45
43
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -70,31 +68,25 @@ module.exports = {
|
|
|
70
68
|
}
|
|
71
69
|
)
|
|
72
70
|
);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
undefined,
|
|
93
|
-
undefined,
|
|
94
|
-
range,
|
|
95
|
-
fixInfo
|
|
96
|
-
);
|
|
97
|
-
}
|
|
71
|
+
for (const token of literalAutolinks(params.parsers.micromark.tokens)) {
|
|
72
|
+
const range = [
|
|
73
|
+
token.startColumn,
|
|
74
|
+
token.endColumn - token.startColumn
|
|
75
|
+
];
|
|
76
|
+
const fixInfo = {
|
|
77
|
+
"editColumn": range[0],
|
|
78
|
+
"deleteCount": range[1],
|
|
79
|
+
"insertText": `<${token.text}>`
|
|
80
|
+
};
|
|
81
|
+
addErrorContext(
|
|
82
|
+
onError,
|
|
83
|
+
token.startLine,
|
|
84
|
+
token.text,
|
|
85
|
+
undefined,
|
|
86
|
+
undefined,
|
|
87
|
+
range,
|
|
88
|
+
fixInfo
|
|
89
|
+
);
|
|
98
90
|
}
|
|
99
91
|
}
|
|
100
92
|
};
|
package/lib/md036.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addErrorContext, allPunctuation } = require("../helpers");
|
|
6
|
-
const {
|
|
6
|
+
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
const { filterByTypesCached } = require("./cache");
|
|
8
8
|
|
|
9
|
-
/** @typedef {import("../helpers/micromark.cjs").TokenType} TokenType */
|
|
10
|
-
/** @type {
|
|
11
|
-
const
|
|
12
|
-
[ "emphasis",
|
|
13
|
-
[ "strong",
|
|
14
|
-
]
|
|
9
|
+
/** @typedef {import("../helpers/micromark-helpers.cjs").TokenType} TokenType */
|
|
10
|
+
/** @type {TokenType[][]} */
|
|
11
|
+
const emphasisTypes = [
|
|
12
|
+
[ "emphasis", "emphasisText" ],
|
|
13
|
+
[ "strong", "strongText" ]
|
|
14
|
+
];
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line jsdoc/valid-types
|
|
17
17
|
/** @type import("./markdownlint").Rule */
|
|
@@ -25,25 +25,19 @@ module.exports = {
|
|
|
25
25
|
punctuation = String((punctuation === undefined) ? allPunctuation : punctuation);
|
|
26
26
|
const punctuationRe = new RegExp("[" + punctuation + "]$");
|
|
27
27
|
const paragraphTokens =
|
|
28
|
-
filterByTypesCached([ "paragraph" ])
|
|
29
|
-
filter((token) =>
|
|
28
|
+
filterByTypesCached([ "paragraph" ])
|
|
29
|
+
.filter((token) =>
|
|
30
30
|
(token.parent?.type === "content") && !token.parent?.parent && (token.children.length === 1)
|
|
31
31
|
);
|
|
32
|
-
for (const
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(textToken.children[0].type === "data") &&
|
|
42
|
-
!punctuationRe.test(textToken.text)
|
|
43
|
-
) {
|
|
44
|
-
addErrorContext(onError, textToken.startLine, textToken.text);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
32
|
+
for (const emphasisType of emphasisTypes) {
|
|
33
|
+
const textTokens = getDescendantsByType(paragraphTokens, emphasisType);
|
|
34
|
+
for (const textToken of textTokens) {
|
|
35
|
+
if (
|
|
36
|
+
(textToken.children.length === 1) &&
|
|
37
|
+
(textToken.children[0].type === "data") &&
|
|
38
|
+
!punctuationRe.test(textToken.text)
|
|
39
|
+
) {
|
|
40
|
+
addErrorContext(onError, textToken.startLine, textToken.text);
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
}
|
package/lib/md037.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const { addError } = require("../helpers");
|
|
6
|
-
const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark.cjs");
|
|
6
|
+
const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark-helpers.cjs");
|
|
7
7
|
|
|
8
8
|
// eslint-disable-next-line jsdoc/valid-types
|
|
9
9
|
/** @type import("./markdownlint").Rule */
|