Refactor Token.parent() to Token.parent, add validation tests for parent, fix parent in htmlFlow scenario, improve type saftey slightly.

This commit is contained in:
David Anson 2023-10-19 23:01:31 -07:00
parent 06466905a5
commit 2a56f130c1
9 changed files with 73 additions and 372 deletions

View file

@ -5,6 +5,10 @@
const { addErrorDetailIf } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
/**
* @typedef {import("../helpers/micromark.cjs").Token} Token
*/
module.exports = {
"names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation",
@ -20,13 +24,14 @@ module.exports = {
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ]
);
for (const token of tokens) {
const { startColumn, startLine, type } = token;
const { parent, startColumn, startLine, type } = token;
if (type === "blockQuotePrefix") {
lastBlockQuotePrefix = token;
} else if (type === "listUnordered") {
let nesting = 0;
/** @type {Token | null} */
let current = token;
while ((current = current.parent())) {
while ((current = current.parent)) {
if (current.type === "listUnordered") {
nesting++;
} else if (current.type === "listOrdered") {
@ -41,7 +46,7 @@ module.exports = {
}
} else {
// listItemPrefix
const nesting = unorderedListNesting.get(token.parent());
const nesting = unorderedListNesting.get(parent);
if (nesting !== undefined) {
// listItemPrefix for listUnordered
const expectedIndent =