mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
40
lib/md012.mjs
Normal file
40
lib/md012.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorDetailIf } from "../helpers/helpers.cjs";
|
||||
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD012", "no-multiple-blanks" ],
|
||||
"description": "Multiple consecutive blank lines",
|
||||
"tags": [ "whitespace", "blank_lines" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD012(params, onError) {
|
||||
const maximum = Number(params.config.maximum || 1);
|
||||
const { lines } = params;
|
||||
const codeBlockLineNumbers = new Set();
|
||||
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
|
||||
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
|
||||
}
|
||||
let count = 0;
|
||||
for (const [ lineIndex, line ] of lines.entries()) {
|
||||
const inCode = codeBlockLineNumbers.has(lineIndex + 1);
|
||||
count = (inCode || (line.trim().length > 0)) ? 0 : count + 1;
|
||||
if (maximum < count) {
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
maximum,
|
||||
count,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
"deleteCount": -1
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue