mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD022/MD031/MD032 to report fixInfo for violations, normalize input to fixErrors.
This commit is contained in:
parent
2cd27c58f2
commit
a062e7c6bd
6 changed files with 357 additions and 38 deletions
29
lib/md032.js
29
lib/md032.js
|
|
@ -5,6 +5,8 @@
|
|||
const { addErrorContext, isBlankLine } = require("../helpers");
|
||||
const { flattenedLists } = require("./cache");
|
||||
|
||||
const quotePrefixRe = /^[>\s]*/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD032", "blanks-around-lists" ],
|
||||
"description": "Lists should be surrounded by blank lines",
|
||||
|
|
@ -14,11 +16,34 @@ module.exports = {
|
|||
flattenedLists().filter((list) => !list.nesting).forEach((list) => {
|
||||
const firstIndex = list.open.map[0];
|
||||
if (!isBlankLine(lines[firstIndex - 1])) {
|
||||
addErrorContext(onError, firstIndex + 1, lines[firstIndex].trim());
|
||||
const line = lines[firstIndex];
|
||||
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
||||
addErrorContext(
|
||||
onError,
|
||||
firstIndex + 1,
|
||||
line.trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"insertText": `${quotePrefix}\n`
|
||||
});
|
||||
}
|
||||
const lastIndex = list.lastLineIndex - 1;
|
||||
if (!isBlankLine(lines[lastIndex + 1])) {
|
||||
addErrorContext(onError, lastIndex + 1, lines[lastIndex].trim());
|
||||
const line = lines[lastIndex];
|
||||
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
||||
addErrorContext(
|
||||
onError,
|
||||
lastIndex + 1,
|
||||
line.trim(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
"lineNumber": lastIndex + 2,
|
||||
"insertText": `${quotePrefix}\n`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue