Move call to mapAliasToRuleNames higher in the stack to avoid re-computing multiple times for the same input.

This commit is contained in:
David Anson 2023-03-12 20:49:41 -07:00
parent 32324b7aea
commit e8a85c91f2
2 changed files with 22 additions and 7 deletions

View file

@ -509,6 +509,8 @@ function getEnabledRulesPerLineNumber(
* Lints a string containing Markdown content.
*
* @param {Rule[]} ruleList List of rules.
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
* names.
* @param {string} name Identifier for the content.
* @param {string} content Markdown content.
* @param {Object} md Instance of markdown-it.
@ -523,6 +525,7 @@ function getEnabledRulesPerLineNumber(
*/
function lintContent(
ruleList,
aliasToRuleNames,
name,
content,
md,
@ -548,7 +551,7 @@ function lintContent(
noInlineConfig,
config,
configParsers,
mapAliasToRuleNames(ruleList)
aliasToRuleNames
);
// Parse content into parser tokens
const markdownitTokens = md.parse(content, {});
@ -792,6 +795,8 @@ function lintContent(
* Lints a file containing Markdown content.
*
* @param {Rule[]} ruleList List of rules.
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
* names.
* @param {string} file Path of file to lint.
* @param {Object} md Instance of markdown-it.
* @param {Configuration} config Configuration object.
@ -807,6 +812,7 @@ function lintContent(
*/
function lintFile(
ruleList,
aliasToRuleNames,
file,
md,
config,
@ -825,6 +831,7 @@ function lintFile(
}
return lintContent(
ruleList,
aliasToRuleNames,
file,
content,
md,
@ -887,6 +894,7 @@ function lintInput(options, synchronous, callback) {
md.use(...plugin);
}
const fs = options.fs || require("node:fs");
const aliasToRuleNames = mapAliasToRuleNames(ruleList);
const results = newResults(ruleList);
let done = false;
let concurrency = 0;
@ -914,6 +922,7 @@ function lintInput(options, synchronous, callback) {
currentItem = files.shift();
lintFile(
ruleList,
aliasToRuleNames,
currentItem,
md,
config,
@ -931,6 +940,7 @@ function lintInput(options, synchronous, callback) {
concurrency++;
lintContent(
ruleList,
aliasToRuleNames,
currentItem,
strings[currentItem] || "",
md,