Update MD022/blanks-around-headings to allow passing -1 for lines_above/lines_below to allow any number of blank lines in that direction (fixes #546).

This commit is contained in:
David Anson 2023-08-06 15:24:35 -07:00
parent f079df140c
commit 809841098d
12 changed files with 273 additions and 58 deletions

View file

@ -32,45 +32,53 @@ module.exports = {
for (const heading of headings) {
const { startLine, endLine } = heading;
const line = lines[startLine - 1].trim();
let actualAbove = 0;
for (let i = 0; i < linesAbove; i++) {
if (isBlankLine(lines[startLine - 2 - i])) {
actualAbove++;
// Check lines above
if (linesAbove >= 0) {
let actualAbove = 0;
for (let i = 0; i < linesAbove; i++) {
if (isBlankLine(lines[startLine - 2 - i])) {
actualAbove++;
}
}
addErrorDetailIf(
onError,
startLine,
linesAbove,
actualAbove,
"Above",
line,
null,
{
"insertText":
getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
}
);
}
addErrorDetailIf(
onError,
startLine,
linesAbove,
actualAbove,
"Above",
line,
null,
{
"insertText":
getBlockQuote(lines[startLine - 2], linesAbove - actualAbove)
}
);
let actualBelow = 0;
for (let i = 0; i < linesBelow; i++) {
if (isBlankLine(lines[endLine + i])) {
actualBelow++;
// Check lines below
if (linesBelow >= 0) {
let actualBelow = 0;
for (let i = 0; i < linesBelow; i++) {
if (isBlankLine(lines[endLine + i])) {
actualBelow++;
}
}
addErrorDetailIf(
onError,
startLine,
linesBelow,
actualBelow,
"Below",
line,
null,
{
"lineNumber": endLine + 1,
"insertText":
getBlockQuote(lines[endLine], linesBelow - actualBelow)
}
);
}
addErrorDetailIf(
onError,
startLine,
linesBelow,
actualBelow,
"Below",
line,
null,
{
"lineNumber": endLine + 1,
"insertText":
getBlockQuote(lines[endLine], linesBelow - actualBelow)
}
);
}
}
};