mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Refactor to remove micromark helper matchAndGetTokensByType.
This commit is contained in:
parent
2ea3f95fd1
commit
87daa5b06c
4 changed files with 66 additions and 184 deletions
|
|
@ -475,31 +475,6 @@ function getTokenTextByType(tokens, type) {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines a list of Micromark tokens matches and returns a subset.
|
||||
*
|
||||
* @param {Token[]} tokens Micromark tokens.
|
||||
* @param {TokenType[]} matchTypes Types to match.
|
||||
* @param {TokenType[]} [resultTypes] Types to return.
|
||||
* @returns {Token[] | null} Matching tokens.
|
||||
*/
|
||||
function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
|
||||
if (tokens.length !== matchTypes.length) {
|
||||
return null;
|
||||
}
|
||||
resultTypes = resultTypes || matchTypes;
|
||||
const result = [];
|
||||
// eslint-disable-next-line unicorn/no-for-loop
|
||||
for (let i = 0; i < matchTypes.length; i++) {
|
||||
if (tokens[i].type !== matchTypes[i]) {
|
||||
return null;
|
||||
} else if (resultTypes.includes(matchTypes[i])) {
|
||||
result.push(tokens[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set containing token types that do not contain content.
|
||||
*
|
||||
|
|
@ -531,6 +506,5 @@ module.exports = {
|
|||
getTokenTextByType,
|
||||
inHtmlFlow,
|
||||
isHtmlFlowComment,
|
||||
matchAndGetTokensByType,
|
||||
nonContentTokens
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue