mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-02-28 07:44:07 +01:00
Refactor to remove micromark helper getTokenTextByType, update getDescendantsByType to allow sub-arrays.
This commit is contained in:
parent
0f210d5c1a
commit
8cbbed8e79
7 changed files with 44 additions and 94 deletions
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError, addErrorContext } = require("../helpers");
|
||||
const { getDescendantsByType, getTokenTextByType } = require("../helpers/micromark.cjs");
|
||||
const { getDescendantsByType } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
|
|
@ -20,14 +20,14 @@ module.exports = {
|
|||
const fencedCodes = filterByTypesCached([ "codeFenced" ]);
|
||||
for (const fencedCode of fencedCodes) {
|
||||
const openingFence = getDescendantsByType(fencedCode, [ "codeFencedFence" ])[0];
|
||||
const { children, startLine, text } = openingFence;
|
||||
const info = getTokenTextByType(children, "codeFencedFenceInfo");
|
||||
const { startLine, text } = openingFence;
|
||||
const info = getDescendantsByType(openingFence, [ "codeFencedFenceInfo" ])[0]?.text;
|
||||
if (!info) {
|
||||
addErrorContext(onError, startLine, text);
|
||||
} else if ((allowed.length > 0) && !allowed.includes(info)) {
|
||||
addError(onError, startLine, `"${info}" is not allowed`);
|
||||
}
|
||||
if (languageOnly && getTokenTextByType(children, "codeFencedFenceMeta")) {
|
||||
if (languageOnly && getDescendantsByType(openingFence, [ "codeFencedFenceMeta" ]).length > 0) {
|
||||
addError(onError, startLine, `Info string contains more than language: "${text}"`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue