mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Refactor MD032/blanks-around-lists to remove redundant micromark flattenedChildren function.
This commit is contained in:
parent
84e664e86e
commit
96a36de713
3 changed files with 11 additions and 42 deletions
|
|
@ -1360,23 +1360,6 @@ function filterByHtmlTokens(tokens) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of all nested child tokens.
|
|
||||||
*
|
|
||||||
* @param {Token} parent Micromark token.
|
|
||||||
* @returns {Token[]} Flattened children.
|
|
||||||
*/
|
|
||||||
function flattenedChildren(parent) {
|
|
||||||
var result = [];
|
|
||||||
var pending = _toConsumableArray(parent.children);
|
|
||||||
var token = null;
|
|
||||||
while (token = pending.shift()) {
|
|
||||||
result.push(token);
|
|
||||||
pending.unshift.apply(pending, _toConsumableArray(token.children));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the heading level of a Micromark heading tokan.
|
* Gets the heading level of a Micromark heading tokan.
|
||||||
*
|
*
|
||||||
|
|
@ -1471,7 +1454,6 @@ module.exports = {
|
||||||
filterByHtmlTokens: filterByHtmlTokens,
|
filterByHtmlTokens: filterByHtmlTokens,
|
||||||
filterByPredicate: filterByPredicate,
|
filterByPredicate: filterByPredicate,
|
||||||
filterByTypes: filterByTypes,
|
filterByTypes: filterByTypes,
|
||||||
flattenedChildren: flattenedChildren,
|
|
||||||
getHeadingLevel: getHeadingLevel,
|
getHeadingLevel: getHeadingLevel,
|
||||||
getHtmlTagInfo: getHtmlTagInfo,
|
getHtmlTagInfo: getHtmlTagInfo,
|
||||||
getMicromarkEvents: getMicromarkEvents,
|
getMicromarkEvents: getMicromarkEvents,
|
||||||
|
|
@ -4850,8 +4832,7 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
|
||||||
blockquotePrefixRe = _require.blockquotePrefixRe,
|
blockquotePrefixRe = _require.blockquotePrefixRe,
|
||||||
isBlankLine = _require.isBlankLine;
|
isBlankLine = _require.isBlankLine;
|
||||||
var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
|
var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
|
||||||
filterByPredicate = _require2.filterByPredicate,
|
filterByPredicate = _require2.filterByPredicate;
|
||||||
flattenedChildren = _require2.flattenedChildren;
|
|
||||||
var nonContentTokens = new Set(["blockQuoteMarker", "blockQuotePrefix", "blockQuotePrefixWhitespace", "lineEnding", "lineEndingBlank", "linePrefix", "listItemIndent"]);
|
var nonContentTokens = new Set(["blockQuoteMarker", "blockQuotePrefix", "blockQuotePrefixWhitespace", "lineEnding", "lineEndingBlank", "linePrefix", "listItemIndent"]);
|
||||||
var isList = function isList(token) {
|
var isList = function isList(token) {
|
||||||
return token.type === "listOrdered" || token.type === "listUnordered";
|
return token.type === "listOrdered" || token.type === "listUnordered";
|
||||||
|
|
@ -4889,7 +4870,10 @@ module.exports = {
|
||||||
|
|
||||||
// Find the "visual" end of the list
|
// Find the "visual" end of the list
|
||||||
var endLine = list.endLine;
|
var endLine = list.endLine;
|
||||||
var _iterator2 = _createForOfIteratorHelper(flattenedChildren(list).reverse()),
|
var flattenedChildren = filterByPredicate(list.children, function () {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
var _iterator2 = _createForOfIteratorHelper(flattenedChildren.reverse()),
|
||||||
_step2;
|
_step2;
|
||||||
try {
|
try {
|
||||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||||
|
|
|
||||||
|
|
@ -235,23 +235,6 @@ function filterByHtmlTokens(tokens) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of all nested child tokens.
|
|
||||||
*
|
|
||||||
* @param {Token} parent Micromark token.
|
|
||||||
* @returns {Token[]} Flattened children.
|
|
||||||
*/
|
|
||||||
function flattenedChildren(parent) {
|
|
||||||
const result = [];
|
|
||||||
const pending = [ ...parent.children ];
|
|
||||||
let token = null;
|
|
||||||
while ((token = pending.shift())) {
|
|
||||||
result.push(token);
|
|
||||||
pending.unshift(...token.children);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the heading level of a Micromark heading tokan.
|
* Gets the heading level of a Micromark heading tokan.
|
||||||
*
|
*
|
||||||
|
|
@ -348,7 +331,6 @@ module.exports = {
|
||||||
filterByHtmlTokens,
|
filterByHtmlTokens,
|
||||||
filterByPredicate,
|
filterByPredicate,
|
||||||
filterByTypes,
|
filterByTypes,
|
||||||
flattenedChildren,
|
|
||||||
getHeadingLevel,
|
getHeadingLevel,
|
||||||
getHtmlTagInfo,
|
getHtmlTagInfo,
|
||||||
getMicromarkEvents,
|
getMicromarkEvents,
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
const { addErrorContext, blockquotePrefixRe, isBlankLine } =
|
const { addErrorContext, blockquotePrefixRe, isBlankLine } =
|
||||||
require("../helpers");
|
require("../helpers");
|
||||||
const { filterByPredicate, flattenedChildren } =
|
const { filterByPredicate } = require("../helpers/micromark.cjs");
|
||||||
require("../helpers/micromark.cjs");
|
|
||||||
|
|
||||||
const nonContentTokens = new Set([
|
const nonContentTokens = new Set([
|
||||||
"blockQuoteMarker",
|
"blockQuoteMarker",
|
||||||
|
|
@ -59,7 +58,11 @@ module.exports = {
|
||||||
|
|
||||||
// Find the "visual" end of the list
|
// Find the "visual" end of the list
|
||||||
let endLine = list.endLine;
|
let endLine = list.endLine;
|
||||||
for (const child of flattenedChildren(list).reverse()) {
|
const flattenedChildren = filterByPredicate(
|
||||||
|
list.children,
|
||||||
|
() => true
|
||||||
|
);
|
||||||
|
for (const child of flattenedChildren.reverse()) {
|
||||||
if (!nonContentTokens.has(child.type)) {
|
if (!nonContentTokens.has(child.type)) {
|
||||||
endLine = child.endLine;
|
endLine = child.endLine;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue