import postcss from "postcss" import { getTagLocalName, getStaticBodyText, isLiteralNode, isHTMLTextNode } from "@herb-tools/core" import { Location } from "@herb-tools/core" import { BaseRuleVisitor } from "../utils/rule-utils.js" import { ParserRule } from "../types.js" import type { ParseResult, HTMLElementNode, Position } from "@herb-tools/core" import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js" class NoEmptyCSSRuleVisitor extends BaseRuleVisitor { visitHTMLElementNode(node: HTMLElementNode): void { if (getTagLocalName(node) === "style") { const css = this.staticCSS(node) if (css !== null) { this.check(node, css) } } super.visitHTMLElementNode(node) } private check(node: HTMLElementNode, css: string): void { let root: postcss.Root try { root = postcss.parse(css) } catch { return } const base = node.open_tag?.location?.end ?? null root.walkRules((rule) => { if (rule.nodes.length > 0) return const selector = rule.selector.trim() const start = rule.source?.start?.offset ?? null const end = rule.source?.end?.offset ?? null const length = start !== null && end !== null ? end - start : selector.length this.addOffense( `The \`${selector}\` rule in this \`