Update helpers.flattenLists to provide correct lastLineIndex for lists with an empty last item (fixes #529).

This commit is contained in:
David Anson 2022-06-07 22:16:34 -07:00
parent 4560ccc1cd
commit 85d720cefc
6 changed files with 175 additions and 10 deletions

View file

@ -395,7 +395,7 @@ module.exports.flattenLists = function flattenLists(tokens) {
else if (token.type === "blockquote_close") {
nesting = nestingStack.pop();
}
else if (token.map) {
if (token.map) {
// Track last token with map
lastWithMap = token;
}

View file

@ -393,7 +393,8 @@ module.exports.flattenLists = function flattenLists(tokens) {
nesting = 0;
} else if (token.type === "blockquote_close") {
nesting = nestingStack.pop();
} else if (token.map) {
}
if (token.map) {
// Track last token with map
lastWithMap = token;
}

View file

@ -1,10 +1,10 @@
#
-
(bare list item marker)
(bare list item marker {MD032:3})
1.
(bare list item marker)
(bare list item marker {MD032:6})
-a
(not a list item)
@ -16,6 +16,6 @@
1. a
- a
- a {MD030}
1. a
1. a {MD030}

49
test/lists-incomplete.md Normal file
View file

@ -0,0 +1,49 @@
# Lists Incomplete
Text
- Item
-
Text
-
- Item
Text
- Item
-
- Item
Text
- Item
-
-
Text
1. Item
1.
Text
1.
1. Item
Text
1. Item
1.
1. Item
Text
1. Item
1.
1.
Text
{MD047}

View file

@ -915,14 +915,50 @@ Generated by [AVA](https://avajs.dev).
'list-marker-space',
],
},
{
errorContext: '-',
errorDetail: null,
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 4,
},
lineNumber: 3,
ruleDescription: 'Lists should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md032',
ruleNames: [
'MD032',
'blanks-around-lists',
],
},
{
errorContext: '1.',
errorDetail: null,
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 7,
},
lineNumber: 6,
ruleDescription: 'Lists should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md032',
ruleNames: [
'MD032',
'blanks-around-lists',
],
},
],
fixed: `#␊
-␊
(bare list item marker)␊
(bare list item marker {MD032:3})␊
1.␊
(bare list item marker)␊
(bare list item marker {MD032:6})␊
-a␊
(not a list item)␊
@ -934,9 +970,9 @@ Generated by [AVA](https://avajs.dev).
1. a␊
- a␊
- a {MD030}
1. a␊
1. a {MD030}
`,
}
@ -25582,6 +25618,85 @@ Generated by [AVA](https://avajs.dev).
`,
}
## lists-incomplete.md
> Snapshot 1
{
errors: [
{
errorContext: null,
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
editColumn: 8,
insertText: `␊
`,
},
lineNumber: 49,
ruleDescription: 'Files should end with a single newline character',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047',
ruleNames: [
'MD047',
'single-trailing-newline',
],
},
],
fixed: `# Lists Incomplete␊
Text␊
- Item␊
-␊
Text␊
-␊
- Item␊
Text␊
- Item␊
-␊
- Item␊
Text␊
- Item␊
-␊
-␊
Text␊
1. Item␊
1.␊
Text␊
1.␊
1. Item␊
Text␊
1. Item␊
1.␊
1. Item␊
Text␊
1. Item␊
1.␊
1.␊
Text␊
{MD047}␊
`,
}
## lists-with-commented-items.md
> Snapshot 1