Skip to content

Commit 8ad4698

Browse files
committed
Update MD032/blanks-around-lists to ignore (end-appended) undefined reference tokens when determining the last line of a list (fixes #1453).
1 parent 599b687 commit 8ad4698

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

helpers/micromark-helpers.cjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ function addRangeToSet(set, start, end) {
7878
* Filter a list of Micromark tokens by predicate.
7979
*
8080
* @param {Token[]} tokens Micromark tokens.
81-
* @param {AllowedPredicate} [allowed] Allowed token predicate.
81+
* @param {AllowedPredicate} allowed Allowed token predicate.
8282
* @param {TransformPredicate} [transformChildren] Transform predicate.
8383
* @returns {Token[]} Filtered tokens.
8484
*/
8585
function filterByPredicate(tokens, allowed, transformChildren) {
86-
allowed = allowed || (() => true);
8786
const result = [];
8887
const queue = [
8988
{
@@ -278,7 +277,11 @@ const nonContentTokens = new Set([
278277
"lineEnding",
279278
"lineEndingBlank",
280279
"linePrefix",
281-
"listItemIndent"
280+
"listItemIndent",
281+
"undefinedReference",
282+
"undefinedReferenceCollapsed",
283+
"undefinedReferenceFull",
284+
"undefinedReferenceShortcut"
282285
]);
283286

284287
module.exports = {

lib/md032.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ export default {
4545
}
4646

4747
// Find the "visual" end of the list
48+
const flattenedChildren = filterByPredicate(
49+
list.children,
50+
(token) => !nonContentTokens.has(token.type),
51+
(token) => nonContentTokens.has(token.type) ? [] : token.children
52+
);
4853
let endLine = list.endLine;
49-
const flattenedChildren = filterByPredicate(list.children);
50-
for (const child of flattenedChildren.reverse()) {
51-
if (!nonContentTokens.has(child.type)) {
52-
endLine = child.endLine;
53-
break;
54-
}
54+
if (flattenedChildren.length > 0) {
55+
endLine = flattenedChildren[flattenedChildren.length - 1].endLine;
5556
}
5657

5758
// Look for a blank line below the list

test/lists_without_blank_lines.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ text
8888

8989
<p>* Not a list</p>
9090

91+
1. Undefined reference token
92+
<pre>
93+
[()]
94+
</pre>
95+
9196
<!-- markdownlint-configure-file {
9297
"no-inline-html": false,
9398
"ul-style": false,

test/snapshots/markdownlint-test-scenarios.mjs.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37346,7 +37346,7 @@ Generated by [AVA](https://avajs.dev).
3734637346
insertText: `␊
3734737347
`,
3734837348
},
37349-
lineNumber: 98,
37349+
lineNumber: 103,
3735037350
ruleDescription: 'Files should end with a single newline character',
3735137351
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md047.md',
3735237352
ruleNames: [
@@ -37457,6 +37457,11 @@ Generated by [AVA](https://avajs.dev).
3745737457
3745837458
<p>* Not a list</p>␊
3745937459
37460+
1. Undefined reference token␊
37461+
<pre>␊
37462+
[()]␊
37463+
</pre>␊
37464+
3746037465
<!-- markdownlint-configure-file {␊
3746137466
"no-inline-html": false,␊
3746237467
"ul-style": false,␊
Binary file not shown.

0 commit comments

Comments
 (0)