mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Update MD041/first-line-heading to avoid scanning every token with Array.filter.
This commit is contained in:
parent
8baa843ce3
commit
95f82760ce
1 changed files with 12 additions and 6 deletions
|
@ -11,10 +11,15 @@ export default {
|
|||
"parser": "micromark",
|
||||
"function": function MD041(params, onError) {
|
||||
const level = Number(params.config.level || 1);
|
||||
if (!frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title)) {
|
||||
params.parsers.micromark.tokens
|
||||
.filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token))
|
||||
.every((token) => {
|
||||
const { tokens } = params.parsers.micromark;
|
||||
if (
|
||||
!frontMatterHasTitle(
|
||||
params.frontMatterLines,
|
||||
params.config.front_matter_title
|
||||
)
|
||||
) {
|
||||
for (const token of tokens) {
|
||||
if (!nonContentTokens.has(token.type) && !isHtmlFlowComment(token)) {
|
||||
let isError = true;
|
||||
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
|
||||
isError = (getHeadingLevel(token) !== level);
|
||||
|
@ -26,8 +31,9 @@ export default {
|
|||
if (isError) {
|
||||
addErrorContext(onError, token.startLine, params.lines[token.startLine - 1]);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue