Add parsers object to RuleParams type, annotate every rule definition with Rule type for better type validation.

This commit is contained in:
David Anson 2024-02-27 20:42:09 -08:00
parent 996d88a9b4
commit 12c4f79604
54 changed files with 363 additions and 59 deletions

View file

@ -6,6 +6,8 @@ const { addError, addErrorContext } = require("../helpers");
const { filterByTypes, getTokenTextByType, tokenIfType } =
require("../helpers/micromark.cjs");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
"names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified",
@ -14,7 +16,8 @@ module.exports = {
let allowed = params.config.allowed_languages;
allowed = Array.isArray(allowed) ? allowed : [];
const languageOnly = !!params.config.language_only;
const fencedCodes = filterByTypes(params.parsers.micromark.tokens, [ "codeFenced" ]);
// eslint-disable-next-line dot-notation
const fencedCodes = filterByTypes(params.parsers["micromark"].tokens, [ "codeFenced" ]);
for (const fencedCode of fencedCodes) {
const openingFence = tokenIfType(fencedCode.children[0], "codeFencedFence");
if (openingFence) {