import { getTagLocalName, getStaticAttributeValue, hasAttributeValue, HELPER_REGISTRY, HELPER_BY_SOURCE } from "@herb-tools/core" import type { ParseResult, ParserOptions, HTMLElementNode, HTMLAttributeNode } from "@herb-tools/core" import { BaseRuleVisitor, findElementAttribute, isJavaScriptTagElement } from "../utils/rule-utils.js" import { ParserRule } from "../types.js" import type { UnboundLintOffense, LintContext, FullRuleConfig } from "../types.js" const HELPERS_WITH_CSP_NONCE_SUPPORT = [ HELPER_REGISTRY["javascript_include_tag"].source, HELPER_REGISTRY["javascript_tag"].source, ] class RequireScriptNonceVisitor extends BaseRuleVisitor { visitHTMLElementNode(node: HTMLElementNode): void { if (getTagLocalName(node) === "script") { this.checkScriptNonce(node) } super.visitHTMLElementNode(node) } private checkScriptNonce(node: HTMLElementNode): void { if (!isJavaScriptTagElement(node)) return if (findElementAttribute(node, "src")) return const nonceAttribute = findElementAttribute(node, "nonce") if (!nonceAttribute || !hasAttributeValue(nonceAttribute)) { this.addOffense(this.missingNonceMessage(), node.tag_name!.location) return } this.checkLiteralNonceOnTagHelper(node, nonceAttribute) } private missingNonceMessage(): string { if (this.context.framework === "actionview") { return "Missing a `nonce` attribute on `