mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update MD032/blanks-around-lists to ignore (end-appended) undefined reference tokens when determining the last line of a list (fixes #1453).
This commit is contained in:
parent
599b687849
commit
8ad4698536
5 changed files with 24 additions and 10 deletions
|
|
@ -78,12 +78,11 @@ function addRangeToSet(set, start, end) {
|
||||||
* Filter a list of Micromark tokens by predicate.
|
* Filter a list of Micromark tokens by predicate.
|
||||||
*
|
*
|
||||||
* @param {Token[]} tokens Micromark tokens.
|
* @param {Token[]} tokens Micromark tokens.
|
||||||
* @param {AllowedPredicate} [allowed] Allowed token predicate.
|
* @param {AllowedPredicate} allowed Allowed token predicate.
|
||||||
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
* @param {TransformPredicate} [transformChildren] Transform predicate.
|
||||||
* @returns {Token[]} Filtered tokens.
|
* @returns {Token[]} Filtered tokens.
|
||||||
*/
|
*/
|
||||||
function filterByPredicate(tokens, allowed, transformChildren) {
|
function filterByPredicate(tokens, allowed, transformChildren) {
|
||||||
allowed = allowed || (() => true);
|
|
||||||
const result = [];
|
const result = [];
|
||||||
const queue = [
|
const queue = [
|
||||||
{
|
{
|
||||||
|
|
@ -278,7 +277,11 @@ const nonContentTokens = new Set([
|
||||||
"lineEnding",
|
"lineEnding",
|
||||||
"lineEndingBlank",
|
"lineEndingBlank",
|
||||||
"linePrefix",
|
"linePrefix",
|
||||||
"listItemIndent"
|
"listItemIndent",
|
||||||
|
"undefinedReference",
|
||||||
|
"undefinedReferenceCollapsed",
|
||||||
|
"undefinedReferenceFull",
|
||||||
|
"undefinedReferenceShortcut"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,14 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the "visual" end of the list
|
// Find the "visual" end of the list
|
||||||
|
const flattenedChildren = filterByPredicate(
|
||||||
|
list.children,
|
||||||
|
(token) => !nonContentTokens.has(token.type),
|
||||||
|
(token) => nonContentTokens.has(token.type) ? [] : token.children
|
||||||
|
);
|
||||||
let endLine = list.endLine;
|
let endLine = list.endLine;
|
||||||
const flattenedChildren = filterByPredicate(list.children);
|
if (flattenedChildren.length > 0) {
|
||||||
for (const child of flattenedChildren.reverse()) {
|
endLine = flattenedChildren[flattenedChildren.length - 1].endLine;
|
||||||
if (!nonContentTokens.has(child.type)) {
|
|
||||||
endLine = child.endLine;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for a blank line below the list
|
// Look for a blank line below the list
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,11 @@ text
|
||||||
|
|
||||||
<p>* Not a list</p>
|
<p>* Not a list</p>
|
||||||
|
|
||||||
|
1. Undefined reference token
|
||||||
|
<pre>
|
||||||
|
[()]
|
||||||
|
</pre>
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"no-inline-html": false,
|
"no-inline-html": false,
|
||||||
"ul-style": false,
|
"ul-style": false,
|
||||||
|
|
|
||||||
|
|
@ -37346,7 +37346,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
insertText: `␊
|
insertText: `␊
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
lineNumber: 98,
|
lineNumber: 103,
|
||||||
ruleDescription: 'Files should end with a single newline character',
|
ruleDescription: 'Files should end with a single newline character',
|
||||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md047.md',
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md047.md',
|
||||||
ruleNames: [
|
ruleNames: [
|
||||||
|
|
@ -37457,6 +37457,11 @@ Generated by [AVA](https://avajs.dev).
|
||||||
␊
|
␊
|
||||||
<p>* Not a list</p>␊
|
<p>* Not a list</p>␊
|
||||||
␊
|
␊
|
||||||
|
1. Undefined reference token␊
|
||||||
|
<pre>␊
|
||||||
|
[()]␊
|
||||||
|
</pre>␊
|
||||||
|
␊
|
||||||
<!-- markdownlint-configure-file {␊
|
<!-- markdownlint-configure-file {␊
|
||||||
"no-inline-html": false,␊
|
"no-inline-html": false,␊
|
||||||
"ul-style": false,␊
|
"ul-style": false,␊
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue