2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2024-08-17 17:58:16 -07:00
|
|
|
const { addErrorDetailIf } = require("../helpers");
|
|
|
|
|
const { addRangeToSet, filterByTypes } = require("../helpers/micromark.cjs");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2024-02-27 20:42:09 -08:00
|
|
|
// eslint-disable-next-line jsdoc/valid-types
|
|
|
|
|
/** @type import("./markdownlint").Rule */
|
2018-01-21 21:44:25 -08:00
|
|
|
module.exports = {
|
|
|
|
|
"names": [ "MD012", "no-multiple-blanks" ],
|
|
|
|
|
"description": "Multiple consecutive blank lines",
|
|
|
|
|
"tags": [ "whitespace", "blank_lines" ],
|
2024-08-17 17:58:16 -07:00
|
|
|
"parser": "micromark",
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD012(params, onError) {
|
2020-01-25 18:40:39 -08:00
|
|
|
const maximum = Number(params.config.maximum || 1);
|
2024-08-17 17:58:16 -07:00
|
|
|
const { lines, parsers } = params;
|
|
|
|
|
const codeBlockLineNumbers = new Set();
|
|
|
|
|
for (const codeBlock of filterByTypes(parsers.micromark.tokens, [ "codeFenced", "codeIndented" ])) {
|
|
|
|
|
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
|
|
|
|
}
|
2018-04-27 22:05:34 -07:00
|
|
|
let count = 0;
|
2024-08-17 17:58:16 -07:00
|
|
|
for (const [ lineIndex, line ] of lines.entries()) {
|
|
|
|
|
const inCode = codeBlockLineNumbers.has(lineIndex + 1);
|
2020-09-06 20:34:10 -07:00
|
|
|
count = (inCode || (line.trim().length > 0)) ? 0 : count + 1;
|
2018-01-21 21:44:25 -08:00
|
|
|
if (maximum < count) {
|
2019-08-24 22:55:51 -07:00
|
|
|
addErrorDetailIf(
|
|
|
|
|
onError,
|
|
|
|
|
lineIndex + 1,
|
|
|
|
|
maximum,
|
|
|
|
|
count,
|
2024-08-17 17:58:16 -07:00
|
|
|
undefined,
|
|
|
|
|
undefined,
|
|
|
|
|
undefined,
|
2019-08-24 22:55:51 -07:00
|
|
|
{
|
|
|
|
|
"deleteCount": -1
|
2024-08-17 17:58:16 -07:00
|
|
|
}
|
|
|
|
|
);
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
2024-08-17 17:58:16 -07:00
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
|
};
|