mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-29 03:58:48 +01:00
Refactor to remove helpers addErrorContextForLine and blockquotePrefixRe, add micromark helper getBlockQuotePrefixText.
This commit is contained in:
parent
29ebb28f10
commit
5182911acc
6 changed files with 170 additions and 152 deletions
24
lib/md022.js
24
lib/md022.js
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } = require("../helpers");
|
||||
const { getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
|
||||
const { addErrorDetailIf, isBlankLine } = require("../helpers");
|
||||
const { getBlockQuotePrefixText, getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
const defaultLines = 1;
|
||||
|
|
@ -21,15 +21,6 @@ const getLinesFunction = (linesParam) => {
|
|||
return () => lines;
|
||||
};
|
||||
|
||||
const getBlockQuote = (str, count) => (
|
||||
(str || "")
|
||||
.match(blockquotePrefixRe)[0]
|
||||
.trimEnd()
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
.concat("\n")
|
||||
.repeat(count)
|
||||
);
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
module.exports = {
|
||||
|
|
@ -41,6 +32,7 @@ module.exports = {
|
|||
const getLinesAbove = getLinesFunction(params.config.lines_above);
|
||||
const getLinesBelow = getLinesFunction(params.config.lines_below);
|
||||
const { lines } = params;
|
||||
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
||||
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
||||
const { startLine, endLine } = heading;
|
||||
const line = lines[startLine - 1].trim();
|
||||
|
|
@ -65,8 +57,9 @@ module.exports = {
|
|||
line,
|
||||
undefined,
|
||||
{
|
||||
"insertText": getBlockQuote(
|
||||
lines[startLine - 2],
|
||||
"insertText": getBlockQuotePrefixText(
|
||||
blockQuotePrefixes,
|
||||
startLine - 1,
|
||||
linesAbove - actualAbove
|
||||
)
|
||||
}
|
||||
|
|
@ -94,8 +87,9 @@ module.exports = {
|
|||
undefined,
|
||||
{
|
||||
"lineNumber": endLine + 1,
|
||||
"insertText": getBlockQuote(
|
||||
lines[endLine],
|
||||
"insertText": getBlockQuotePrefixText(
|
||||
blockQuotePrefixes,
|
||||
endLine + 1,
|
||||
linesBelow - actualBelow
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue