mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Refactor micromark helper getTokenTextByType to be more efficient, remove tokenIfType helper for being redundant.
This commit is contained in:
parent
b749d9fbb4
commit
2ea3f95fd1
6 changed files with 82 additions and 120 deletions
28
lib/md048.js
28
lib/md048.js
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorDetailIf, fencedCodeBlockStyleFor } = require("../helpers");
|
||||
const { tokenIfType } = require("../helpers/micromark.cjs");
|
||||
const { getDescendantsByType } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
|
|
@ -18,22 +18,18 @@ module.exports = {
|
|||
let expectedStyle = style;
|
||||
const codeFenceds = filterByTypesCached([ "codeFenced" ]);
|
||||
for (const codeFenced of codeFenceds) {
|
||||
const codeFencedFence = tokenIfType(codeFenced.children[0], "codeFencedFence");
|
||||
if (codeFencedFence) {
|
||||
const codeFencedFenceSequence = tokenIfType(codeFencedFence.children[0], "codeFencedFenceSequence");
|
||||
if (codeFencedFenceSequence) {
|
||||
const { startLine, text } = codeFencedFenceSequence;
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = fencedCodeBlockStyleFor(text);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
expectedStyle,
|
||||
fencedCodeBlockStyleFor(text)
|
||||
);
|
||||
}
|
||||
const codeFencedFenceSequence =
|
||||
getDescendantsByType(codeFenced, [ "codeFencedFence", "codeFencedFenceSequence" ])[0];
|
||||
const { startLine, text } = codeFencedFenceSequence;
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = fencedCodeBlockStyleFor(text);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
startLine,
|
||||
expectedStyle,
|
||||
fencedCodeBlockStyleFor(text)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue