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
|
|
|
|
|
|
|
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])) {
|
|
|
|
addErrorContext(onError, firstIndex + 1, lines[firstIndex].trim());
|
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])) {
|
|
|
|
addErrorContext(onError, lastIndex + 1, lines[lastIndex].trim());
|
2019-01-21 18:21:36 -08:00
|
|
|
}
|
|
|
|
});
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|