Update MD022/MD031/MD032 to report fixInfo for violations, normalize input to fixErrors.

This commit is contained in:
David Anson 2019-08-28 21:47:07 -07:00
parent 2cd27c58f2
commit a062e7c6bd
6 changed files with 357 additions and 38 deletions

View file

@ -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`
});
}
});
}