mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Refactor to remove micromark helper getSiblingTokens for simpler code and better performance.
This commit is contained in:
parent
4436d84b55
commit
996d88a9b4
4 changed files with 88 additions and 140 deletions
43
lib/md027.js
43
lib/md027.js
|
|
@ -3,35 +3,32 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { getSiblingTokens } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
|
||||
module.exports = {
|
||||
"names": ["MD027", "no-multiple-space-blockquote"],
|
||||
"description": "Multiple spaces after blockquote symbol",
|
||||
"tags": ["blockquote", "whitespace", "indentation"],
|
||||
"function": function MD027(params, onError) {
|
||||
for (const siblings of getSiblingTokens(params.parsers.micromark.tokens)) {
|
||||
let previousType = null;
|
||||
for (const token of siblings) {
|
||||
const { type } = token;
|
||||
if ((type === "linePrefix") && (previousType === "blockQuotePrefix")) {
|
||||
const { startColumn, startLine, text } = token;
|
||||
const { length } = text;
|
||||
const line = params.lines[startLine - 1];
|
||||
addErrorContext(
|
||||
onError,
|
||||
startLine,
|
||||
line,
|
||||
null,
|
||||
null,
|
||||
[ startColumn, length ],
|
||||
{
|
||||
"editColumn": startColumn,
|
||||
"deleteCount": length
|
||||
}
|
||||
);
|
||||
}
|
||||
previousType = type;
|
||||
const { tokens } = params.parsers.micromark;
|
||||
for (const token of filterByTypes(tokens, [ "linePrefix" ])) {
|
||||
const siblings = token.parent?.children || tokens;
|
||||
if (siblings[siblings.indexOf(token) - 1]?.type === "blockQuotePrefix") {
|
||||
const { startColumn, startLine, text } = token;
|
||||
const { length } = text;
|
||||
const line = params.lines[startLine - 1];
|
||||
addErrorContext(
|
||||
onError,
|
||||
startLine,
|
||||
line,
|
||||
null,
|
||||
null,
|
||||
[ startColumn, length ],
|
||||
{
|
||||
"editColumn": startColumn,
|
||||
"deleteCount": length
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue