/**
* FIXME: remove this comments and import when below issue is fixed.
* This import is necessary for type generation due to a bug in the TypeScript compiler.
* See: https://github.com/microsoft/TypeScript/issues/42873
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { TSESLint } from "@typescript-eslint/utils";
import type { TSESTree as T } from "@typescript-eslint/utils";
import { parse, parseFragment } from "parse5";
import type { DefaultTreeAdapterMap } from "parse5";
import { isValidHTMLNesting } from "validate-html-nesting";
import { createRule } from "../compat";
import { isDOMElementName, jsxPropName } from "../utils";
type MessageIds = "invalidNesting" | "invalidNestingInserted";
type Options = [];
/**
* `
` from a parsed document, used as the parsing context so fragments are
* interpreted the way `innerHTML` would interpret them.
*/
type ParentNode = DefaultTreeAdapterMap["parentNode"];
type ChildNode = DefaultTreeAdapterMap["childNode"];
const htmlElement = parse("")
.childNodes[1] as ParentNode;
const bodyContext = htmlElement.childNodes[1] as ParentNode;
type Namespace = "html" | "svg" | "math";
const rewriteCache = new Map();
const tableWrappers: Record = {
caption: ["table"],
colgroup: ["table"],
tbody: ["table"],
thead: ["table"],
tfoot: ["table"],
tr: ["table", "tbody"],
td: ["table", "tbody", "tr"],
th: ["table", "tbody", "tr"],
};
/** Void elements take no end tag, and the parser would read `` as another ` `. */
const voidElements = new Set([
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr",
]);
/** parse5 lowercases tag names outside SVG, so `` comes back as `foreignobject`. */
const isTag = (node: ChildNode, tag: string): boolean =>
node.nodeName.toLowerCase() === tag.toLowerCase();
/**
* Does the HTML parser refuse to keep `child` as a direct child of `parent`?
*
* `validate-html-nesting` alone is not enough to answer this. Its tables encode
* the spec's *content model* — `` belongs in ``, ``
* in ``, `