mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +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",
|
"parser": "micromark",
|
||||||
"function": function MD041(params, onError) {
|
"function": function MD041(params, onError) {
|
||||||
const level = Number(params.config.level || 1);
|
const level = Number(params.config.level || 1);
|
||||||
if (!frontMatterHasTitle(params.frontMatterLines, params.config.front_matter_title)) {
|
const { tokens } = params.parsers.micromark;
|
||||||
params.parsers.micromark.tokens
|
if (
|
||||||
.filter((token) => !nonContentTokens.has(token.type) && !isHtmlFlowComment(token))
|
!frontMatterHasTitle(
|
||||||
.every((token) => {
|
params.frontMatterLines,
|
||||||
|
params.config.front_matter_title
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
for (const token of tokens) {
|
||||||
|
if (!nonContentTokens.has(token.type) && !isHtmlFlowComment(token)) {
|
||||||
let isError = true;
|
let isError = true;
|
||||||
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
|
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
|
||||||
isError = (getHeadingLevel(token) !== level);
|
isError = (getHeadingLevel(token) !== level);
|
||||||
|
@ -26,8 +31,9 @@ export default {
|
||||||
if (isError) {
|
if (isError) {
|
||||||
addErrorContext(onError, token.startLine, params.lines[token.startLine - 1]);
|
addErrorContext(onError, token.startLine, params.lines[token.startLine - 1]);
|
||||||
}
|
}
|
||||||
return false;
|
break;
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue