mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +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
42
lib/md032.js
42
lib/md032.js
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContextForLine, isBlankLine } = require("../helpers");
|
||||
const { filterByPredicate, nonContentTokens } = require("../helpers/micromark-helpers.cjs");
|
||||
const { addErrorContext, isBlankLine } = require("../helpers");
|
||||
const { filterByPredicate, getBlockQuotePrefixText, nonContentTokens } = require("../helpers/micromark-helpers.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
const isList = (token) => (
|
||||
(token.type === "listOrdered") || (token.type === "listUnordered")
|
||||
|
|
@ -18,6 +19,7 @@ module.exports = {
|
|||
"parser": "micromark",
|
||||
"function": function MD032(params, onError) {
|
||||
const { lines, parsers } = params;
|
||||
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
||||
|
||||
// For every top-level list...
|
||||
const topLevelLists = filterByPredicate(
|
||||
|
|
@ -30,13 +32,18 @@ module.exports = {
|
|||
for (const list of topLevelLists) {
|
||||
|
||||
// Look for a blank line above the list
|
||||
const firstIndex = list.startLine - 1;
|
||||
if (!isBlankLine(lines[firstIndex - 1])) {
|
||||
addErrorContextForLine(
|
||||
const firstLineNumber = list.startLine;
|
||||
if (!isBlankLine(lines[firstLineNumber - 2])) {
|
||||
addErrorContext(
|
||||
onError,
|
||||
// @ts-ignore
|
||||
lines,
|
||||
firstIndex
|
||||
firstLineNumber,
|
||||
lines[firstLineNumber - 1].trim(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, firstLineNumber)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -51,14 +58,19 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Look for a blank line below the list
|
||||
const lastIndex = endLine - 1;
|
||||
if (!isBlankLine(lines[lastIndex + 1])) {
|
||||
addErrorContextForLine(
|
||||
const lastLineNumber = endLine;
|
||||
if (!isBlankLine(lines[lastLineNumber])) {
|
||||
addErrorContext(
|
||||
onError,
|
||||
// @ts-ignore
|
||||
lines,
|
||||
lastIndex,
|
||||
lastIndex + 2
|
||||
lastLineNumber,
|
||||
lines[lastLineNumber - 1].trim(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
"lineNumber": lastLineNumber + 1,
|
||||
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, lastLineNumber)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue