2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, isBlankLine } = require("../helpers");
|
2019-04-10 21:26:59 -07:00
|
|
|
const { flattenedLists } = require("./cache");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-08-28 21:47:07 -07:00
|
|
|
const quotePrefixRe = /^[>\s]*/;
|
|
|
|
|
2018-01-21 21:44:25 -08:00
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD032", "blanks-around-lists" ],
|
|
|
|
"description": "Lists should be surrounded by blank lines",
|
|
|
|
"tags": [ "bullet", "ul", "ol", "blank_lines" ],
|
|
|
|
"function": function MD032(params, onError) {
|
2019-03-20 21:48:18 -07:00
|
|
|
const { lines } = params;
|
2019-04-10 21:26:59 -07:00
|
|
|
flattenedLists().filter((list) => !list.nesting).forEach((list) => {
|
2019-03-20 21:48:18 -07:00
|
|
|
const firstIndex = list.open.map[0];
|
|
|
|
if (!isBlankLine(lines[firstIndex - 1])) {
|
2019-08-28 21:47:07 -07:00
|
|
|
const line = lines[firstIndex];
|
2021-02-06 19:55:22 -08:00
|
|
|
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
2019-08-28 21:47:07 -07:00
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
firstIndex + 1,
|
|
|
|
line.trim(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
"insertText": `${quotePrefix}\n`
|
|
|
|
});
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2019-03-20 21:48:18 -07:00
|
|
|
const lastIndex = list.lastLineIndex - 1;
|
|
|
|
if (!isBlankLine(lines[lastIndex + 1])) {
|
2019-08-28 21:47:07 -07:00
|
|
|
const line = lines[lastIndex];
|
2021-02-06 19:55:22 -08:00
|
|
|
const quotePrefix = line.match(quotePrefixRe)[0].trimEnd();
|
2019-08-28 21:47:07 -07:00
|
|
|
addErrorContext(
|
|
|
|
onError,
|
|
|
|
lastIndex + 1,
|
|
|
|
line.trim(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
"lineNumber": lastIndex + 2,
|
|
|
|
"insertText": `${quotePrefix}\n`
|
|
|
|
});
|
2019-01-21 18:21:36 -08:00
|
|
|
}
|
|
|
|
});
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|