Use @type to provide typing for all instances of params.parsers.micromark.tokens.

This commit is contained in:
David Anson 2024-02-28 21:01:23 -08:00
parent aee8c2d1d3
commit 828ae3541a
23 changed files with 284 additions and 160 deletions

View file

@ -72,15 +72,15 @@ module.exports = {
"description": "Link fragments should be valid",
"tags": [ "links" ],
"function": function MD051(params, onError) {
// eslint-disable-next-line dot-notation
const { tokens } = params.parsers["micromark"];
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").Token[] */
const micromarkTokens =
// @ts-ignore
params.parsers.micromark.tokens;
const fragments = new Map();
// Process headings
const headingTexts = filterByTypes(
tokens,
[ "atxHeadingText", "setextHeadingText" ]
);
const headingTexts = filterByTypes(micromarkTokens, [ "atxHeadingText", "setextHeadingText" ]);
for (const headingText of headingTexts) {
const fragment = convertHeadingToHTMLFragment(headingText);
if (fragment !== "#") {
@ -100,7 +100,7 @@ module.exports = {
}
// Process HTML anchors
for (const token of filterByTypes(tokens, [ "htmlText" ])) {
for (const token of filterByTypes(micromarkTokens, [ "htmlText" ])) {
const htmlTagInfo = getHtmlTagInfo(token);
if (htmlTagInfo && !htmlTagInfo.close) {
const anchorMatch = idRe.exec(token.text) ||
@ -117,7 +117,7 @@ module.exports = {
[ "definition", "definitionDestinationString" ]
];
for (const [ parentType, definitionType ] of parentChilds) {
const links = filterByTypes(tokens, [ parentType ]);
const links = filterByTypes(micromarkTokens, [ parentType ]);
for (const link of links) {
const definitions = filterByTypes(link.children, [ definitionType ]);
for (const definition of definitions) {