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

@ -4177,25 +4177,33 @@ module.exports = {
var startLine = heading.startLine,
endLine = heading.endLine;
var line = lines[startLine - 1].trim();
var actualAbove = 0;
for (var i = 0; i < linesAbove; i++) {
if (isBlankLine(lines[startLine - 2 - i])) {
actualAbove++;
// Check lines above
if (linesAbove >= 0) {
var actualAbove = 0;
for (var 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)
});
var actualBelow = 0;
for (var _i = 0; _i < linesBelow; _i++) {
if (isBlankLine(lines[endLine + _i])) {
actualBelow++;
// Check lines below
if (linesBelow >= 0) {
var actualBelow = 0;
for (var _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)
});
}
} catch (err) {
_iterator.e(err);