2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorDetailIf, forEachLine } = require("../helpers");
|
2019-04-10 21:26:59 -07:00
|
|
|
const { lineMetadata } = require("./cache");
|
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-03-09 16:17:50 -08:00
|
|
|
"parser": "none",
|
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);
|
2018-04-27 22:05:34 -07:00
|
|
|
let count = 0;
|
2019-04-10 21:26:59 -07:00
|
|
|
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
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,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
"deleteCount": -1
|
|
|
|
});
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|