@stll/oxlint-plugin 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bun-test-hygiene.cjs +2 -2
- package/dist/bun-test-hygiene.cjs.map +1 -1
- package/dist/bun-test-hygiene.d.cts +3 -2
- package/dist/bun-test-hygiene.d.mts +3 -2
- package/dist/bun-test-hygiene.mjs +2 -2
- package/dist/bun-test-hygiene.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/no-any-casts.cjs +2 -2
- package/dist/no-any-casts.cjs.map +1 -1
- package/dist/no-any-casts.d.cts +3 -2
- package/dist/no-any-casts.d.mts +3 -2
- package/dist/no-any-casts.mjs +2 -2
- package/dist/no-any-casts.mjs.map +1 -1
- package/dist/no-checkout-writes-in-tests.cjs +2 -2
- package/dist/no-checkout-writes-in-tests.cjs.map +1 -1
- package/dist/no-checkout-writes-in-tests.d.cts +3 -2
- package/dist/no-checkout-writes-in-tests.d.mts +3 -2
- package/dist/no-checkout-writes-in-tests.mjs +2 -2
- package/dist/no-checkout-writes-in-tests.mjs.map +1 -1
- package/dist/no-dangerous-type-assertions.cjs +2 -2
- package/dist/no-dangerous-type-assertions.cjs.map +1 -1
- package/dist/no-dangerous-type-assertions.d.cts +3 -2
- package/dist/no-dangerous-type-assertions.d.mts +3 -2
- package/dist/no-dangerous-type-assertions.mjs +2 -2
- package/dist/no-dangerous-type-assertions.mjs.map +1 -1
- package/dist/no-partial-record-satisfies.cjs +2 -2
- package/dist/no-partial-record-satisfies.cjs.map +1 -1
- package/dist/no-partial-record-satisfies.d.cts +3 -2
- package/dist/no-partial-record-satisfies.d.mts +3 -2
- package/dist/no-partial-record-satisfies.mjs +2 -2
- package/dist/no-partial-record-satisfies.mjs.map +1 -1
- package/dist/no-raw-route-query-client.cjs +2 -2
- package/dist/no-raw-route-query-client.cjs.map +1 -1
- package/dist/no-raw-route-query-client.d.cts +3 -2
- package/dist/no-raw-route-query-client.d.mts +3 -2
- package/dist/no-raw-route-query-client.mjs +2 -2
- package/dist/no-raw-route-query-client.mjs.map +1 -1
- package/dist/no-real-network-in-tests.cjs +2 -2
- package/dist/no-real-network-in-tests.cjs.map +1 -1
- package/dist/no-real-network-in-tests.d.cts +3 -2
- package/dist/no-real-network-in-tests.d.mts +3 -2
- package/dist/no-real-network-in-tests.mjs +2 -2
- package/dist/no-real-network-in-tests.mjs.map +1 -1
- package/dist/no-real-timer-waits-in-tests.cjs +2 -2
- package/dist/no-real-timer-waits-in-tests.cjs.map +1 -1
- package/dist/no-real-timer-waits-in-tests.d.cts +3 -2
- package/dist/no-real-timer-waits-in-tests.d.mts +3 -2
- package/dist/no-real-timer-waits-in-tests.mjs +2 -2
- package/dist/no-real-timer-waits-in-tests.mjs.map +1 -1
- package/dist/no-unsafe-inner-html.cjs +13 -3
- package/dist/no-unsafe-inner-html.cjs.map +1 -1
- package/dist/no-unsafe-inner-html.d.cts +3 -2
- package/dist/no-unsafe-inner-html.d.mts +3 -2
- package/dist/no-unsafe-inner-html.mjs +13 -3
- package/dist/no-unsafe-inner-html.mjs.map +1 -1
- package/dist/no-unseeded-random-in-tests.cjs +2 -2
- package/dist/no-unseeded-random-in-tests.cjs.map +1 -1
- package/dist/no-unseeded-random-in-tests.d.cts +3 -2
- package/dist/no-unseeded-random-in-tests.d.mts +3 -2
- package/dist/no-unseeded-random-in-tests.mjs +2 -2
- package/dist/no-unseeded-random-in-tests.mjs.map +1 -1
- package/dist/no-wall-clock-bound.cjs +2 -2
- package/dist/no-wall-clock-bound.cjs.map +1 -1
- package/dist/no-wall-clock-bound.d.cts +3 -2
- package/dist/no-wall-clock-bound.d.mts +3 -2
- package/dist/no-wall-clock-bound.mjs +2 -2
- package/dist/no-wall-clock-bound.mjs.map +1 -1
- package/dist/no-wall-clock-in-tests.cjs +2 -2
- package/dist/no-wall-clock-in-tests.cjs.map +1 -1
- package/dist/no-wall-clock-in-tests.d.cts +3 -2
- package/dist/no-wall-clock-in-tests.d.mts +3 -2
- package/dist/no-wall-clock-in-tests.mjs +2 -2
- package/dist/no-wall-clock-in-tests.mjs.map +1 -1
- package/dist/require-loader-prefetch.cjs +2 -2
- package/dist/require-loader-prefetch.cjs.map +1 -1
- package/dist/require-loader-prefetch.d.cts +3 -2
- package/dist/require-loader-prefetch.d.mts +3 -2
- package/dist/require-loader-prefetch.mjs +2 -2
- package/dist/require-loader-prefetch.mjs.map +1 -1
- package/dist/test-rule-utils.cjs.map +1 -1
- package/dist/test-rule-utils.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unsafe-inner-html.mjs","names":["exhaustive"],"sources":["../src/no-unsafe-inner-html.ts"],"sourcesContent":["// Forbid injecting un-proven HTML into the DOM.\n//\n// Raw HTML may only reach the DOM from a value that is provably sanitized or\n// escaped. This rule covers common DOM and JSX sinks while allowing explicit\n// sanitizer calls and narrowly scoped provenance comments.\n//\n// Sinks, all sharing one allowlist:\n// • `__html` of a `dangerouslySetInnerHTML` object, whether the object is a\n// JSX attribute value or a property of any object literal (props passed\n// to `createElement` / `jsx()`, or spread into JSX).\n// • assignment to `innerHTML`, `outerHTML` or `srcdoc`, dot or static\n// bracket notation, and the same keys in an `Object.assign` source.\n// • the JSX `srcDoc` attribute.\n// • `insertAdjacentHTML`, `setHTMLUnsafe`, `createContextualFragment`,\n// `setAttribute(\"srcdoc\", …)` / `setAttributeNS(…, \"srcdoc\", …)`,\n// and `write` / `writeln` on a document.\n//\n// In the default `allowlist` policy, a value is allowed when it is:\n// • a static string Literal or TemplateLiteral whose interpolations are all\n// independently static, OR\n// • passed through the shared HTML sanitizer allowlist (`escapeHtml`,\n// `escapeXml`, `sanitizeHtml`, `sanitizeDom`, `DOMPurify.sanitize`, and\n// related established names), including `.value` / `.data` / `.html`\n// result accessors; OR\n// • annotated by a `// safe-html: <provenance>` comment with non-empty text\n// on the line directly above the sink. One comment covers one sink: a\n// second sink starting on the same line needs its own annotation.\n// The `provenance` policy omits the sanitizer-name allowlist and requires the\n// comment for dynamic sanitizer results as well.\n//\n// The sanitizer allowlist preserves the shared plugin contract. For dynamic\n// values outside that list, function names are not proof: a local identity\n// function can be named `sanitizeHtml`. Add explicit provenance at the sink\n// until the codebase has a branded SafeHtml boundary.\n\nimport type { Scope, Variable } from \"@oxlint/plugins\";\nimport { eslintCompatPlugin } from \"@oxlint/plugins\";\n\nimport type { AstNode, LiteralArgumentResolution } from \"./utils.ts\";\nimport {\n getPropertyName,\n invokedCallee,\n isAstNode,\n isIdentifier,\n isStringLiteral,\n memberPropertyName,\n resolveLiteralArraySpreads,\n staticStringValue,\n unwrapExpression,\n} from \"./utils.ts\";\n\ntype DomElementProducer = {\n name: string;\n kind: \"property\" | \"method\" | \"collection\" | \"collection-property\";\n receiver: \"document\" | \"element\" | \"either\";\n};\n\n// DOM element provenance and the generated equivalence corpus share this table.\nexport const DOM_ELEMENT_PRODUCERS = [\n { name: \"body\", kind: \"property\", receiver: \"document\" },\n { name: \"head\", kind: \"property\", receiver: \"document\" },\n { name: \"documentElement\", kind: \"property\", receiver: \"document\" },\n { name: \"activeElement\", kind: \"property\", receiver: \"document\" },\n { name: \"scrollingElement\", kind: \"property\", receiver: \"document\" },\n { name: \"fullscreenElement\", kind: \"property\", receiver: \"document\" },\n { name: \"createElement\", kind: \"method\", receiver: \"document\" },\n { name: \"createElementNS\", kind: \"method\", receiver: \"document\" },\n { name: \"getElementById\", kind: \"method\", receiver: \"document\" },\n { name: \"querySelector\", kind: \"method\", receiver: \"either\" },\n { name: \"closest\", kind: \"method\", receiver: \"element\" },\n { name: \"elementFromPoint\", kind: \"method\", receiver: \"document\" },\n { name: \"getElementsByClassName\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByTagName\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByTagNameNS\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByName\", kind: \"collection\", receiver: \"document\" },\n { name: \"querySelectorAll\", kind: \"collection\", receiver: \"either\" },\n { name: \"children\", kind: \"collection-property\", receiver: \"element\" },\n { name: \"parentElement\", kind: \"property\", receiver: \"element\" },\n { name: \"firstElementChild\", kind: \"property\", receiver: \"element\" },\n { name: \"lastElementChild\", kind: \"property\", receiver: \"element\" },\n { name: \"nextElementSibling\", kind: \"property\", receiver: \"element\" },\n { name: \"previousElementSibling\", kind: \"property\", receiver: \"element\" },\n { name: \"offsetParent\", kind: \"property\", receiver: \"element\" },\n] as const satisfies readonly DomElementProducer[];\n\n// The provenance text after the marker must be non-empty.\nconst WAIVER_RE = /^\\s*safe-html:\\s*\\S/u;\n\nexport const REACT_HTML_PROPS = [\n { name: \"dangerouslySetInnerHTML\", kind: \"payload\", htmlKey: \"__html\" },\n { name: \"srcDoc\", kind: \"value\" },\n { name: \"srcdoc\", kind: \"value\" },\n] as const;\ntype ReactHtmlProp = (typeof REACT_HTML_PROPS)[number];\nexport const REACT_ELEMENT_FACTORIES: ReadonlySet<string> = new Set([\n \"createElement\",\n \"React.createElement\",\n \"jsx\",\n \"jsxs\",\n \"jsxDEV\",\n]);\nconst HTML_PROPERTIES: ReadonlySet<string> = new Set([\n \"innerHTML\",\n \"outerHTML\",\n \"srcdoc\",\n]);\n// Methods whose first argument is parsed as HTML.\nconst HTML_FIRST_ARGUMENT_METHODS: ReadonlySet<string> = new Set([\n \"createContextualFragment\",\n \"setHTMLUnsafe\",\n]);\nexport const DOCUMENT_WRITE_METHODS: ReadonlySet<string> = new Set([\n \"write\",\n \"writeln\",\n]);\nexport const HTML_ATTRIBUTE_SINKS = [\n { name: \"setAttribute\", namespaceIndex: null, nameIndex: 0, valueIndex: 1 },\n { name: \"setAttributeNS\", namespaceIndex: 0, nameIndex: 1, valueIndex: 2 },\n] as const;\nconst DOCUMENT_MEMBERS: ReadonlySet<string> = new Set([\n \"contentDocument\",\n \"document\",\n \"ownerDocument\",\n]);\nconst FILE_SYSTEM_MODULES: ReadonlySet<string> = new Set([\n \"fs\",\n \"fs/promises\",\n \"node:fs\",\n \"node:fs/promises\",\n]);\nconst CHILD_PROCESS_MODULES: ReadonlySet<string> = new Set([\n \"child_process\",\n \"node:child_process\",\n]);\n// Calls that return a ChildProcess, whose stdin is a writable stream.\nconst CHILD_PROCESS_FACTORIES: ReadonlySet<string> = new Set([\n \"exec\",\n \"execFile\",\n \"fork\",\n \"spawn\",\n]);\nconst HTML_SANITIZER_LEAF_RE =\n /^(?:escape(?:html|xml)|sanitize(?:html|dom)|purify(?:html|dom)|dompurify)$/iu;\nconst SANITIZER_RESULT_MEMBERS = new Set([\"value\", \"data\", \"html\"]);\nconst SANITIZER_POLICY = {\n allowlist: \"allowlist\",\n provenance: \"provenance\",\n} as const;\nconst SANITIZER_POLICY_VALUES = Object.values(SANITIZER_POLICY);\ntype SanitizerPolicy = (typeof SANITIZER_POLICY)[keyof typeof SANITIZER_POLICY];\n\nconst sanitizerPolicyFrom = (option: unknown): SanitizerPolicy => {\n if (option === undefined) {\n return SANITIZER_POLICY.allowlist;\n }\n if (typeof option !== \"object\" || option === null || Array.isArray(option)) {\n throw new Error(\"no-unsafe-inner-html options must be an object\");\n }\n const policy = Reflect.get(option, \"sanitizerPolicy\");\n switch (policy) {\n case undefined:\n case SANITIZER_POLICY.allowlist:\n return SANITIZER_POLICY.allowlist;\n case SANITIZER_POLICY.provenance:\n return SANITIZER_POLICY.provenance;\n default:\n throw new Error(`unknown sanitizer policy: ${String(policy)}`);\n }\n};\n\n// Use the same static member-name resolution for sinks and safe-value proofs.\nconst staticCalleeName = (node: unknown): string | null => {\n const expression = unwrapExpression(node);\n if (isIdentifier(expression)) return expression.name;\n if (expression?.type !== \"MemberExpression\") return null;\n const receiver = staticCalleeName(expression.object);\n const property = memberPropertyName(expression);\n return receiver === null || property === null\n ? null\n : `${receiver}.${property}`;\n};\n\nconst isSanitizerCall = (node: unknown): boolean => {\n if (!isAstNode(node) || node.type !== \"CallExpression\") {\n return false;\n }\n const dotted = staticCalleeName(node.callee);\n if (dotted === null) {\n return false;\n }\n const parts = dotted.split(\".\");\n const leaf = parts.at(-1);\n if (leaf === undefined) {\n return false;\n }\n if (HTML_SANITIZER_LEAF_RE.test(leaf)) {\n return true;\n }\n return leaf === \"sanitize\" && /^dompurify$/iu.test(parts.at(-2) ?? \"\");\n};\n\nconst isSanitizerResult = (node: unknown): boolean => {\n const expression = unwrapExpression(node);\n if (expression?.type !== \"MemberExpression\") {\n return false;\n }\n const property = memberPropertyName(expression);\n return (\n property !== null &&\n SANITIZER_RESULT_MEMBERS.has(property) &&\n isSanitizerCall(expression.object)\n );\n};\n\ntype Located = { loc: { start: { line: number } } };\n\nconst hasLocation = (node: unknown): node is Located =>\n typeof node === \"object\" &&\n node !== null &&\n \"loc\" in node &&\n typeof node.loc === \"object\" &&\n node.loc !== null &&\n \"start\" in node.loc &&\n typeof node.loc.start === \"object\" &&\n node.loc.start !== null &&\n \"line\" in node.loc.start &&\n typeof node.loc.start.line === \"number\";\n\n// A node without location data never matches a waiver line.\nconst startLine = (node: unknown): number =>\n hasLocation(node) ? node.loc.start.line : Number.NaN;\n\ntype WaiverComment = {\n value: string;\n loc: { end: { line: number } };\n};\n\nconst isWaiverComment = (value: unknown): value is WaiverComment =>\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n typeof value.value === \"string\" &&\n WAIVER_RE.test(value.value) &&\n \"loc\" in value &&\n typeof value.loc === \"object\" &&\n value.loc !== null;\n\nconst jsxAttributeName = (node: unknown): string | null =>\n isAstNode(node) &&\n node.type === \"JSXIdentifier\" &&\n typeof node.name === \"string\"\n ? node.name\n : null;\n\n// A value is proven safe by its own static shape, independent of comments.\nconst isProvenSafeValue = (\n node: unknown,\n sanitizerPolicy: SanitizerPolicy,\n): boolean => {\n const expression = unwrapExpression(node);\n if (expression === null) {\n return false;\n }\n if (isStringLiteral(expression)) {\n return true;\n }\n if (\n sanitizerPolicy === SANITIZER_POLICY.allowlist &&\n (isSanitizerCall(expression) || isSanitizerResult(expression))\n ) {\n return true;\n }\n return (\n expression.type === \"TemplateLiteral\" &&\n Array.isArray(expression.expressions) &&\n expression.expressions.every((entry) =>\n isProvenSafeValue(entry, sanitizerPolicy),\n )\n );\n};\n\n// The static key of an object-literal Property: `a`, `\"a\"`, `[\"a\"]`.\nconst objectPropertyKey = (property: unknown): string | null => {\n if (!isAstNode(property)) {\n return null;\n }\n if (property.computed === true) {\n return staticStringValue(property.key);\n }\n return getPropertyName(property.key);\n};\n\nconst isOpaqueProperty = (property: AstNode): boolean =>\n property.type === \"SpreadElement\" ||\n (property.type === \"Property\" &&\n property.computed === true &&\n objectPropertyKey(property) === null);\n\nconst objectProperties = (node: unknown): AstNode[] => {\n const expression = unwrapExpression(node);\n if (\n expression?.type !== \"ObjectExpression\" ||\n !Array.isArray(expression.properties)\n ) {\n return [];\n }\n const properties: AstNode[] = [];\n for (const property of expression.properties.filter(isAstNode)) {\n if (\n property.type === \"SpreadElement\" &&\n unwrapExpression(property.argument)?.type === \"ObjectExpression\"\n ) {\n properties.push(...objectProperties(property.argument));\n continue;\n }\n properties.push(property);\n }\n return properties;\n};\n\ntype AppliedArguments = LiteralArgumentResolution;\n\nconst appliedArgumentsFor = (args: unknown[]): AppliedArguments => {\n const applied = unwrapExpression(args.at(1));\n if (\n applied === null ||\n (applied.type === \"Literal\" && applied.value === null) ||\n isIdentifier(applied, \"undefined\")\n ) {\n return { status: \"known\", args: [] };\n }\n if (applied.type !== \"ArrayExpression\" || !Array.isArray(applied.elements)) {\n return { status: \"opaque\", args: [], spread: args.at(1), tail: [] };\n }\n return resolveLiteralArraySpreads(applied.elements);\n};\n\n// The arguments the invoked function receives: `f.call(thisArg, ...args)`\n// shifts them by one; `f.apply(thisArg, [...])` forwards a literal array.\nconst invokedArguments = (call: unknown): AppliedArguments => {\n if (!isAstNode(call)) {\n return { status: \"known\", args: [] };\n }\n const rawArguments = Array.isArray(call.arguments) ? call.arguments : [];\n const resolved = resolveLiteralArraySpreads(rawArguments);\n const callee = unwrapExpression(call.callee);\n if (callee?.type !== \"MemberExpression\") return resolved;\n const method = memberPropertyName(callee);\n if (method === \"call\") {\n return { ...resolved, args: resolved.args.slice(1) };\n }\n if (method !== \"apply\") return resolved;\n if (resolved.status === \"opaque\") {\n if (resolved.args.length >= 2) return appliedArgumentsFor(resolved.args);\n return { ...resolved, args: [], tail: [] };\n }\n return appliedArgumentsFor(resolved.args);\n};\n\nexport default eslintCompatPlugin({\n meta: { name: \"no-unsafe-inner-html\" },\n rules: {\n \"no-unsafe-inner-html\": {\n meta: {\n type: \"problem\",\n schema: [\n {\n type: \"object\",\n properties: {\n sanitizerPolicy: {\n type: \"string\",\n enum: SANITIZER_POLICY_VALUES,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unsafeInnerHtml:\n \"Dynamic HTML injected into the DOM must be static, proven by \" +\n \"the configured sanitizer policy, or have an adjacent \" +\n \"`// safe-html: <provenance>` comment naming the trusted source. \" +\n \"Function names outside the allowlist are not proof because a \" +\n \"local identity function can shadow them.\",\n unsafeInnerHtmlSpread:\n \"Do not spread an object in dangerouslySetInnerHTML. Keep \" +\n \"`__html` inline so this rule can prove the HTML value is \" +\n \"sanitized or escaped.\",\n unsafeInnerHtmlComputedKey:\n \"Do not use an unresolved computed key in \" +\n \"dangerouslySetInnerHTML. Write an explicit `__html` property \" +\n \"so this rule can \" +\n \"prove the HTML value is sanitized or escaped.\",\n },\n },\n createOnce(context) {\n type BindingOptions = {\n node: unknown;\n scope: Scope;\n seen: Set<Variable>;\n };\n type BindingSource = {\n kind: \"expression\" | \"iteration\";\n node: AstNode | null;\n scope: Scope;\n };\n // All document, element and collection checks share one stable-binding path.\n const resolveStableBinding = ({\n node,\n scope,\n seen,\n }: BindingOptions): BindingSource | null => {\n let target = unwrapExpression(node);\n while (isIdentifier(target)) {\n let current: Scope | null = scope;\n let variable: Variable | undefined;\n while (current !== null) {\n variable = current.set.get(target.name);\n if (variable !== undefined) break;\n current = current.upper;\n }\n if (variable === undefined || variable.defs.length === 0) {\n return { kind: \"expression\", node: target, scope };\n }\n if (seen.has(variable)) return null;\n seen.add(variable);\n const definition = variable.defs.at(0);\n // A never-reassigned class or function declaration holds a\n // function, which is neither an element nor a document.\n if (\n variable.defs.length === 1 &&\n (definition?.type === \"ClassName\" ||\n definition?.type === \"FunctionName\") &&\n (definition.node.type === \"ClassDeclaration\" ||\n definition.node.type === \"FunctionDeclaration\") &&\n !variable.references.some((reference) => reference.isWrite())\n ) {\n return {\n kind: \"expression\",\n node: unwrapExpression(definition.node),\n scope,\n };\n }\n if (\n variable.defs.length !== 1 ||\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n variable.references.some(\n (reference) => reference.isWrite() && !reference.init,\n )\n ) {\n return null;\n }\n const declarator = definition.node;\n if (declarator.init !== null) {\n target = unwrapExpression(declarator.init);\n scope = context.sourceCode.getScope(declarator);\n continue;\n }\n const declaration = declarator.parent;\n if (declaration.type !== \"VariableDeclaration\") return null;\n const loop = declaration.parent;\n if (loop.type !== \"ForOfStatement\" || loop.left !== declaration) {\n return null;\n }\n return {\n kind: \"iteration\",\n node: unwrapExpression(loop.right),\n scope: context.sourceCode.getScope(loop.right),\n };\n }\n return { kind: \"expression\", node: target, scope };\n };\n const isKnownNonEmptyNamespace = (\n namespace: unknown,\n scope: Scope,\n ): boolean => {\n const source = resolveStableBinding({\n node: namespace,\n scope,\n seen: new Set<Variable>(),\n });\n if (source?.kind !== \"expression\") return false;\n const text = staticStringValue(source.node);\n // DOM normalizes the empty namespace to null. Unknowns stay checked.\n if (text !== null) return text !== \"\";\n if (source.node?.type !== \"Literal\") return false;\n const { value } = source.node;\n return (\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n );\n };\n\n const variableFor = (\n identifier: { name: string },\n initialScope: Scope,\n ): Variable | undefined => {\n let current: Scope | null = initialScope;\n while (current !== null) {\n const variable = current.set.get(identifier.name);\n if (variable !== undefined) return variable;\n current = current.upper;\n }\n return undefined;\n };\n const isKnownNonDocumentReceiver = (\n node: unknown,\n scope: Scope,\n ): boolean => {\n const isUnshadowedGlobal = (\n identifier: unknown,\n name: string,\n ): boolean =>\n isIdentifier(identifier, name) &&\n variableFor(identifier, scope) === undefined;\n const isFileSystemImport = (identifier: unknown): boolean => {\n if (!isIdentifier(identifier)) return false;\n const variable = variableFor(identifier, scope);\n if (variable?.defs.length !== 1) return false;\n const definition = variable.defs.at(0);\n return (\n definition?.type === \"ImportBinding\" &&\n definition.parent?.type === \"ImportDeclaration\" &&\n FILE_SYSTEM_MODULES.has(definition.parent.source.value)\n );\n };\n // A const bound once to a child process factory call: a node\n // child_process import or the unshadowed Bun.spawn.\n const isChildProcess = (identifier: unknown): boolean => {\n if (!isIdentifier(identifier)) return false;\n const variable = variableFor(identifier, scope);\n const definition = variable?.defs.at(0);\n if (\n variable?.defs.length !== 1 ||\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n definition.node.parent.type !== \"VariableDeclaration\" ||\n definition.node.parent.kind !== \"const\"\n )\n return false;\n const init = unwrapExpression(definition.node.init);\n if (init?.type !== \"CallExpression\") return false;\n const callee = unwrapExpression(init.callee);\n if (callee?.type === \"MemberExpression\")\n return (\n memberPropertyName(callee) === \"spawn\" &&\n isUnshadowedGlobal(unwrapExpression(callee.object), \"Bun\")\n );\n if (!isIdentifier(callee)) return false;\n const factory = variableFor(callee, scope);\n const binding = factory?.defs.at(0);\n return (\n factory?.defs.length === 1 &&\n binding?.type === \"ImportBinding\" &&\n binding.node.type === \"ImportSpecifier\" &&\n binding.node.imported.type === \"Identifier\" &&\n CHILD_PROCESS_FACTORIES.has(binding.node.imported.name) &&\n binding.parent?.type === \"ImportDeclaration\" &&\n CHILD_PROCESS_MODULES.has(binding.parent.source.value)\n );\n };\n const root = unwrapExpression(node);\n if (isUnshadowedGlobal(root, \"Bun\") || isFileSystemImport(root)) {\n return true;\n }\n if (root?.type !== \"MemberExpression\") return false;\n const stream = memberPropertyName(root);\n const owner = unwrapExpression(root.object);\n return (\n ((stream === \"stdout\" || stream === \"stderr\") &&\n isUnshadowedGlobal(owner, \"process\")) ||\n (stream === \"stdin\" && isChildProcess(owner))\n );\n };\n const isDocumentReceiver = (node: unknown, scope: Scope): boolean => {\n if (isKnownNonDocumentReceiver(node, scope)) return false;\n const source = resolveStableBinding({\n node,\n scope,\n seen: new Set<Variable>(),\n });\n if (source === null || source.kind !== \"expression\") return true;\n const receiver = source.node;\n if (isIdentifier(receiver, \"document\")) return true;\n if (receiver?.type !== \"MemberExpression\") return false;\n const name = memberPropertyName(receiver);\n return name !== null && DOCUMENT_MEMBERS.has(name);\n };\n\n const isDocumentSinkReceiver = (\n node: unknown,\n scope: Scope,\n ): boolean => {\n if (isKnownNonDocumentReceiver(node, scope)) return false;\n const receiver = unwrapExpression(node);\n if (!isIdentifier(receiver)) return true;\n let current: Scope | null = scope;\n let variable: Variable | undefined;\n while (current !== null) {\n variable = current.set.get(receiver.name);\n if (variable !== undefined) break;\n current = current.upper;\n }\n if (variable === undefined || variable.defs.length !== 1) return true;\n const definition = variable.defs.at(0);\n if (\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n definition.node.init === null ||\n unwrapExpression(definition.node.init)?.type !==\n \"ObjectExpression\" ||\n definition.node.parent.type !== \"VariableDeclaration\" ||\n definition.node.parent.kind !== \"const\" ||\n variable.scope.variableScope !== scope.variableScope ||\n variable.references.some(\n (reference) => reference.isWrite() && !reference.init,\n )\n ) {\n return true;\n }\n return false;\n };\n type DomTargetOptions = {\n node: unknown;\n scope: Scope;\n seen?: Set<Variable>;\n kind?: \"element\" | \"collection\";\n };\n const isKnownDomTarget = ({\n node,\n scope,\n seen = new Set<Variable>(),\n kind = \"element\",\n }: DomTargetOptions): boolean => {\n const source = resolveStableBinding({ node, scope, seen });\n // An unstable binding may have been reassigned to a DOM target. Fail\n // closed unless the resolver can prove a stable non-DOM value.\n if (source === null) return true;\n if (source.kind === \"iteration\") {\n return (\n kind === \"element\" &&\n isKnownDomTarget({\n node: source.node,\n scope: source.scope,\n seen,\n kind: \"collection\",\n })\n );\n }\n const target = source.node;\n scope = source.scope;\n const hasProducerReceiver = (\n receiver: unknown,\n producer: DomElementProducer,\n ): boolean => {\n if (\n producer.receiver !== \"element\" &&\n isDocumentReceiver(receiver, scope)\n ) {\n return true;\n }\n return (\n producer.receiver !== \"document\" &&\n isKnownDomTarget({ node: receiver, scope, seen })\n );\n };\n const isElementCollection = (collection: unknown): boolean =>\n isKnownDomTarget({\n node: collection,\n scope,\n seen,\n kind: \"collection\",\n });\n if (target?.type === \"MemberExpression\") {\n const property = memberPropertyName(target);\n const producer = DOM_ELEMENT_PRODUCERS.find(\n (entry) =>\n entry.kind ===\n (kind === \"collection\"\n ? \"collection-property\"\n : \"property\") && entry.name === property,\n );\n if (producer !== undefined) {\n return hasProducerReceiver(target.object, producer);\n }\n const index = unwrapExpression(target.property);\n if (\n kind === \"element\" &&\n target.computed === true &&\n index?.type === \"Literal\" &&\n typeof index.value === \"number\" &&\n Number.isInteger(index.value) &&\n index.value >= 0\n ) {\n return isElementCollection(target.object);\n }\n }\n if (target?.type === \"CallExpression\") {\n const callee = invokedCallee(target);\n if (callee?.type !== \"MemberExpression\") return false;\n const method = memberPropertyName(callee);\n if (\n kind === \"element\" &&\n method === \"item\" &&\n isElementCollection(callee.object)\n ) {\n return true;\n }\n const producer = DOM_ELEMENT_PRODUCERS.find(\n (entry) =>\n entry.kind ===\n (kind === \"collection\" ? \"collection\" : \"method\") &&\n entry.name === method,\n );\n return (\n producer !== undefined &&\n hasProducerReceiver(callee.object, producer)\n );\n }\n return kind === \"element\" && isDocumentReceiver(target, scope);\n };\n\n let sanitizerPolicy: SanitizerPolicy = SANITIZER_POLICY.allowlist;\n // Associate waivers after visiting the file, so source position decides\n // the first covered sink even when AST visitors inspect values out of order.\n const waiverLines = new Set<number>();\n type SinkObservation = {\n node: AstNode;\n kind:\n | \"safe\"\n | \"unsafe\"\n | \"opaque-payload-spread\"\n | \"opaque-payload-computed-key\";\n };\n const sinks: SinkObservation[] = [];\n const observeSink = (\n node: unknown,\n kind: SinkObservation[\"kind\"],\n ): void => {\n if (isAstNode(node)) sinks.push({ node, kind });\n };\n const messageIdFor = (kind: SinkObservation[\"kind\"]) => {\n if (kind === \"opaque-payload-spread\") {\n return \"unsafeInnerHtmlSpread\";\n }\n if (kind === \"opaque-payload-computed-key\") {\n return \"unsafeInnerHtmlComputedKey\";\n }\n return \"unsafeInnerHtml\";\n };\n\n const consumeWaiver = (node: unknown): boolean => {\n const line = startLine(node) - 1;\n if (!waiverLines.has(line)) {\n return false;\n }\n waiverLines.delete(line);\n return true;\n };\n\n const reportIfUnsafe = (node: unknown): void => {\n observeSink(\n node,\n isProvenSafeValue(node, sanitizerPolicy) ? \"safe\" : \"unsafe\",\n );\n };\n\n // The value of a `dangerouslySetInnerHTML` prop: an inline object has\n // its `__html` checked and its spreads rejected; anything else is a\n // hoisted payload whose HTML this rule cannot see.\n const checkDangerousPayload = (\n value: unknown,\n htmlKey: string,\n ): void => {\n const expression = unwrapExpression(value);\n if (expression?.type !== \"ObjectExpression\") {\n reportIfUnsafe(value);\n return;\n }\n for (const property of objectProperties(expression)) {\n if (isOpaqueProperty(property)) {\n observeSink(\n property,\n property.type === \"SpreadElement\"\n ? \"opaque-payload-spread\"\n : \"opaque-payload-computed-key\",\n );\n continue;\n }\n if (\n property.type === \"Property\" &&\n objectPropertyKey(property) === htmlKey\n ) {\n reportIfUnsafe(property.value);\n }\n }\n };\n\n const checkReactHtmlProp = (\n prop: ReactHtmlProp,\n value: unknown,\n ): void => {\n switch (prop.kind) {\n case \"payload\":\n checkDangerousPayload(value, prop.htmlKey);\n return;\n case \"value\":\n reportIfUnsafe(value);\n return;\n default: {\n const exhaustive: never = prop;\n throw new Error(`Unknown React HTML prop: ${String(exhaustive)}`);\n }\n }\n };\n\n const checkReactProps = (value: unknown): void => {\n for (const property of objectProperties(value)) {\n if (property.type !== \"Property\") continue;\n const key = objectPropertyKey(property);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === key);\n // Payload properties are checked once by the Property visitor.\n if (prop?.kind === \"value\")\n checkReactHtmlProp(prop, property.value);\n }\n };\n\n const checkHtmlPropertySources = (\n sources: unknown[],\n domTarget: boolean,\n ): void => {\n for (const source of sources) {\n const expression = unwrapExpression(source);\n if (expression?.type !== \"ObjectExpression\") {\n if (domTarget) {\n reportIfUnsafe(source);\n }\n continue;\n }\n for (const property of objectProperties(source)) {\n if (isOpaqueProperty(property)) {\n if (domTarget) {\n reportIfUnsafe(property);\n }\n continue;\n }\n const key =\n property.type === \"Property\"\n ? objectPropertyKey(property)\n : null;\n if (key !== null && HTML_PROPERTIES.has(key)) {\n reportIfUnsafe(property.value);\n }\n }\n }\n };\n\n return {\n before() {\n sanitizerPolicy = sanitizerPolicyFrom(context.options.at(0));\n waiverLines.clear();\n sinks.length = 0;\n },\n \"Program:exit\"() {\n sinks.sort(\n (left, right) => left.node.range[0] - right.node.range[0],\n );\n for (const { node, kind } of sinks) {\n const waived = consumeWaiver(node);\n if (kind === \"safe\" || (kind === \"unsafe\" && waived)) continue;\n context.report({\n node,\n messageId: messageIdFor(kind),\n });\n }\n sinks.length = 0;\n },\n Program(node) {\n const comments: unknown[] = Array.isArray(node.comments)\n ? node.comments\n : [];\n for (const comment of comments) {\n if (isWaiverComment(comment)) {\n waiverLines.add(comment.loc.end.line);\n }\n }\n },\n\n JSXAttribute(node) {\n const name = jsxAttributeName(node.name);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === name);\n if (prop === undefined) return;\n const value = unwrapExpression(node.value);\n checkReactHtmlProp(\n prop,\n value?.type === \"JSXExpressionContainer\"\n ? value.expression\n : value,\n );\n },\n\n JSXSpreadAttribute(node) {\n checkReactProps(node.argument);\n },\n\n // Payload objects remain checked when hoisted or spread into JSX.\n // Direct value props use the JSX and factory props contexts.\n Property(node) {\n const key = objectPropertyKey(node);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === key);\n if (prop?.kind !== \"payload\") return;\n const container = node.parent;\n if (isAstNode(container) && container.type === \"ObjectExpression\") {\n checkReactHtmlProp(prop, node.value);\n }\n },\n\n AssignmentExpression(node) {\n const target = unwrapExpression(node.left);\n if (target?.type !== \"MemberExpression\") {\n return;\n }\n const name = memberPropertyName(target);\n if (name !== null && HTML_PROPERTIES.has(name)) {\n reportIfUnsafe(node.right);\n }\n },\n\n CallExpression(node) {\n const call: unknown = node;\n const callee = isAstNode(call) ? invokedCallee(call) : null;\n const invoked = invokedArguments(node);\n const factory = staticCalleeName(callee);\n if (factory !== null && REACT_ELEMENT_FACTORIES.has(factory)) {\n checkReactProps(invoked.args.at(1));\n return;\n }\n if (callee?.type !== \"MemberExpression\") {\n return;\n }\n const method = memberPropertyName(callee);\n if (method === null) {\n return;\n }\n if (HTML_FIRST_ARGUMENT_METHODS.has(method)) {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n reportIfUnsafe(invoked.args.at(0));\n return;\n }\n if (method === \"insertAdjacentHTML\") {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n reportIfUnsafe(invoked.args.at(1));\n return;\n }\n const attributeSink = HTML_ATTRIBUTE_SINKS.find(\n (entry) => entry.name === method,\n );\n if (attributeSink !== undefined) {\n if (\n attributeSink.namespaceIndex !== null &&\n isKnownNonEmptyNamespace(\n invoked.args.at(attributeSink.namespaceIndex),\n context.sourceCode.getScope(node),\n )\n ) {\n return;\n }\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n const attribute = staticStringValue(\n invoked.args.at(attributeSink.nameIndex),\n );\n if (attribute?.toLowerCase() === \"srcdoc\") {\n reportIfUnsafe(invoked.args.at(attributeSink.valueIndex));\n }\n return;\n }\n if (\n DOCUMENT_WRITE_METHODS.has(method) &&\n isDocumentSinkReceiver(\n callee.object,\n context.sourceCode.getScope(node),\n )\n ) {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n observeSink(\n node,\n invoked.args.every((argument) =>\n isProvenSafeValue(argument, sanitizerPolicy),\n )\n ? \"safe\"\n : \"unsafe\",\n );\n return;\n }\n if (isIdentifier(callee.object, \"Object\") && method === \"assign\") {\n const domTarget = isKnownDomTarget({\n node: invoked.args.at(0),\n scope: context.sourceCode.getScope(node),\n });\n checkHtmlPropertySources(\n [\n ...invoked.args.slice(1),\n ...(invoked.status === \"opaque\" ? invoked.tail : []),\n ],\n domTarget,\n );\n if (invoked.status === \"opaque\" && domTarget) {\n reportIfUnsafe(invoked.spread);\n }\n }\n },\n };\n },\n },\n },\n});\n"],"mappings":";;;AA0DA,MAAa,wBAAwB;CACnC;EAAE,MAAM;EAAQ,MAAM;EAAY,UAAU;CAAW;CACvD;EAAE,MAAM;EAAQ,MAAM;EAAY,UAAU;CAAW;CACvD;EAAE,MAAM;EAAmB,MAAM;EAAY,UAAU;CAAW;CAClE;EAAE,MAAM;EAAiB,MAAM;EAAY,UAAU;CAAW;CAChE;EAAE,MAAM;EAAoB,MAAM;EAAY,UAAU;CAAW;CACnE;EAAE,MAAM;EAAqB,MAAM;EAAY,UAAU;CAAW;CACpE;EAAE,MAAM;EAAiB,MAAM;EAAU,UAAU;CAAW;CAC9D;EAAE,MAAM;EAAmB,MAAM;EAAU,UAAU;CAAW;CAChE;EAAE,MAAM;EAAkB,MAAM;EAAU,UAAU;CAAW;CAC/D;EAAE,MAAM;EAAiB,MAAM;EAAU,UAAU;CAAS;CAC5D;EAAE,MAAM;EAAW,MAAM;EAAU,UAAU;CAAU;CACvD;EAAE,MAAM;EAAoB,MAAM;EAAU,UAAU;CAAW;CACjE;EAAE,MAAM;EAA0B,MAAM;EAAc,UAAU;CAAS;CACzE;EAAE,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AAI,QAAQ,WAAW,UAAU;OAC/B,eAAe,IAAI;OACnB;MACF;MACA,YACE,MACA,QAAQ,KAAK,OAAO,aAClB,kBAAkB,UAAU,eAAe,CAC7C,IACI,SACA,QACN;MACA;KACF;KACA,IAAI,aAAa,OAAO,QAAQ,QAAQ,KAAK,WAAW,UAAU;MAChE,MAAM,YAAY,iBAAiB;OACjC,MAAM,QAAQ,KAAK,GAAG,CAAC;OACvB,OAAO,QAAQ,WAAW,SAAS,IAAI;MACzC,CAAC;MACD,yBACE,CACE,GAAG,QAAQ,KAAK,MAAM,CAAC,GACvB,GAAI,QAAQ,WAAW,WAAW,QAAQ,OAAO,CAAC,CACpD,GACA,SACF;MACA,IAAI,QAAQ,WAAW,YAAY,WACjC,eAAe,QAAQ,MAAM;KAEjC;IACF;GACF;EACF;CACF,EACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"no-unsafe-inner-html.mjs","names":["exhaustive"],"sources":["../src/no-unsafe-inner-html.ts"],"sourcesContent":["// Forbid injecting un-proven HTML into the DOM.\n//\n// Raw HTML may only reach the DOM from a value that is provably sanitized or\n// escaped. This rule covers common DOM and JSX sinks while allowing explicit\n// sanitizer calls and narrowly scoped provenance comments.\n//\n// Sinks, all sharing one allowlist:\n// • `__html` of a `dangerouslySetInnerHTML` object, whether the object is a\n// JSX attribute value or a property of any object literal (props passed\n// to `createElement` / `jsx()`, or spread into JSX).\n// • assignment to `innerHTML`, `outerHTML` or `srcdoc`, dot or static\n// bracket notation, and the same keys in an `Object.assign` source\n// (either branch of a conditional or logical source).\n// • the JSX `srcDoc` attribute.\n// • `insertAdjacentHTML`, `setHTMLUnsafe`, `createContextualFragment`,\n// `setAttribute(\"srcdoc\", …)` / `setAttributeNS(…, \"srcdoc\", …)`,\n// and `write` / `writeln` on a document.\n//\n// In the default `allowlist` policy, a value is allowed when it is:\n// • a static string Literal or TemplateLiteral whose interpolations are all\n// independently static, OR\n// • passed through the shared HTML sanitizer allowlist (`escapeHtml`,\n// `escapeXml`, `sanitizeHtml`, `sanitizeDom`, `DOMPurify.sanitize`, and\n// related established names), including `.value` / `.data` / `.html`\n// result accessors; OR\n// • annotated by a `// safe-html: <provenance>` comment with non-empty text\n// on the line directly above the sink. One comment covers one sink: a\n// second sink starting on the same line needs its own annotation.\n// The `provenance` policy omits the sanitizer-name allowlist and requires the\n// comment for dynamic sanitizer results as well.\n//\n// The sanitizer allowlist preserves the shared plugin contract. For dynamic\n// values outside that list, function names are not proof: a local identity\n// function can be named `sanitizeHtml`. Add explicit provenance at the sink\n// until the codebase has a branded SafeHtml boundary.\n\nimport type { Scope, Variable } from \"@oxlint/plugins\";\nimport { eslintCompatPlugin, type Plugin } from \"@oxlint/plugins\";\n\nimport type { AstNode, LiteralArgumentResolution } from \"./utils.ts\";\nimport {\n getPropertyName,\n invokedCallee,\n isAstNode,\n isIdentifier,\n isStringLiteral,\n memberPropertyName,\n resolveLiteralArraySpreads,\n staticStringValue,\n unwrapExpression,\n} from \"./utils.ts\";\n\ntype DomElementProducer = {\n name: string;\n kind: \"property\" | \"method\" | \"collection\" | \"collection-property\";\n receiver: \"document\" | \"element\" | \"either\";\n};\n\n// DOM element provenance and the generated equivalence corpus share this table.\nexport const DOM_ELEMENT_PRODUCERS = [\n { name: \"body\", kind: \"property\", receiver: \"document\" },\n { name: \"head\", kind: \"property\", receiver: \"document\" },\n { name: \"documentElement\", kind: \"property\", receiver: \"document\" },\n { name: \"activeElement\", kind: \"property\", receiver: \"document\" },\n { name: \"scrollingElement\", kind: \"property\", receiver: \"document\" },\n { name: \"fullscreenElement\", kind: \"property\", receiver: \"document\" },\n { name: \"createElement\", kind: \"method\", receiver: \"document\" },\n { name: \"createElementNS\", kind: \"method\", receiver: \"document\" },\n { name: \"getElementById\", kind: \"method\", receiver: \"document\" },\n { name: \"querySelector\", kind: \"method\", receiver: \"either\" },\n { name: \"closest\", kind: \"method\", receiver: \"element\" },\n { name: \"elementFromPoint\", kind: \"method\", receiver: \"document\" },\n { name: \"getElementsByClassName\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByTagName\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByTagNameNS\", kind: \"collection\", receiver: \"either\" },\n { name: \"getElementsByName\", kind: \"collection\", receiver: \"document\" },\n { name: \"querySelectorAll\", kind: \"collection\", receiver: \"either\" },\n { name: \"children\", kind: \"collection-property\", receiver: \"element\" },\n { name: \"parentElement\", kind: \"property\", receiver: \"element\" },\n { name: \"firstElementChild\", kind: \"property\", receiver: \"element\" },\n { name: \"lastElementChild\", kind: \"property\", receiver: \"element\" },\n { name: \"nextElementSibling\", kind: \"property\", receiver: \"element\" },\n { name: \"previousElementSibling\", kind: \"property\", receiver: \"element\" },\n { name: \"offsetParent\", kind: \"property\", receiver: \"element\" },\n] as const;\n\n// The provenance text after the marker must be non-empty.\nconst WAIVER_RE = /^\\s*safe-html:\\s*\\S/u;\n\nexport const REACT_HTML_PROPS = [\n { name: \"dangerouslySetInnerHTML\", kind: \"payload\", htmlKey: \"__html\" },\n { name: \"srcDoc\", kind: \"value\" },\n { name: \"srcdoc\", kind: \"value\" },\n] as const;\ntype ReactHtmlProp = (typeof REACT_HTML_PROPS)[number];\nexport const REACT_ELEMENT_FACTORIES: ReadonlySet<string> = new Set([\n \"createElement\",\n \"React.createElement\",\n \"jsx\",\n \"jsxs\",\n \"jsxDEV\",\n]);\nconst HTML_PROPERTIES: ReadonlySet<string> = new Set([\n \"innerHTML\",\n \"outerHTML\",\n \"srcdoc\",\n]);\n// Methods whose first argument is parsed as HTML.\nconst HTML_FIRST_ARGUMENT_METHODS: ReadonlySet<string> = new Set([\n \"createContextualFragment\",\n \"setHTMLUnsafe\",\n]);\nexport const DOCUMENT_WRITE_METHODS: ReadonlySet<string> = new Set([\n \"write\",\n \"writeln\",\n]);\nexport const HTML_ATTRIBUTE_SINKS = [\n { name: \"setAttribute\", namespaceIndex: null, nameIndex: 0, valueIndex: 1 },\n { name: \"setAttributeNS\", namespaceIndex: 0, nameIndex: 1, valueIndex: 2 },\n] as const;\nconst DOCUMENT_MEMBERS: ReadonlySet<string> = new Set([\n \"contentDocument\",\n \"document\",\n \"ownerDocument\",\n]);\nconst FILE_SYSTEM_MODULES: ReadonlySet<string> = new Set([\n \"fs\",\n \"fs/promises\",\n \"node:fs\",\n \"node:fs/promises\",\n]);\nconst CHILD_PROCESS_MODULES: ReadonlySet<string> = new Set([\n \"child_process\",\n \"node:child_process\",\n]);\n// Calls that return a ChildProcess, whose stdin is a writable stream.\nconst CHILD_PROCESS_FACTORIES: ReadonlySet<string> = new Set([\n \"exec\",\n \"execFile\",\n \"fork\",\n \"spawn\",\n]);\nconst HTML_SANITIZER_LEAF_RE =\n /^(?:escape(?:html|xml)|sanitize(?:html|dom)|purify(?:html|dom)|dompurify)$/iu;\nconst SANITIZER_RESULT_MEMBERS = new Set([\"value\", \"data\", \"html\"]);\nconst SANITIZER_POLICY = {\n allowlist: \"allowlist\",\n provenance: \"provenance\",\n} as const;\nconst SANITIZER_POLICY_VALUES = Object.values(SANITIZER_POLICY);\ntype SanitizerPolicy = (typeof SANITIZER_POLICY)[keyof typeof SANITIZER_POLICY];\n\nconst sanitizerPolicyFrom = (option: unknown): SanitizerPolicy => {\n if (option === undefined) {\n return SANITIZER_POLICY.allowlist;\n }\n if (typeof option !== \"object\" || option === null || Array.isArray(option)) {\n throw new Error(\"no-unsafe-inner-html options must be an object\");\n }\n const policy = Reflect.get(option, \"sanitizerPolicy\");\n switch (policy) {\n case undefined:\n case SANITIZER_POLICY.allowlist:\n return SANITIZER_POLICY.allowlist;\n case SANITIZER_POLICY.provenance:\n return SANITIZER_POLICY.provenance;\n default:\n throw new Error(`unknown sanitizer policy: ${String(policy)}`);\n }\n};\n\n// Use the same static member-name resolution for sinks and safe-value proofs.\nconst staticCalleeName = (node: unknown): string | null => {\n const expression = unwrapExpression(node);\n if (isIdentifier(expression)) return expression.name;\n if (expression?.type !== \"MemberExpression\") return null;\n const receiver = staticCalleeName(expression.object);\n const property = memberPropertyName(expression);\n return receiver === null || property === null\n ? null\n : `${receiver}.${property}`;\n};\n\nconst isSanitizerCall = (node: unknown): boolean => {\n if (!isAstNode(node) || node.type !== \"CallExpression\") {\n return false;\n }\n const dotted = staticCalleeName(node.callee);\n if (dotted === null) {\n return false;\n }\n const parts = dotted.split(\".\");\n const leaf = parts.at(-1);\n if (leaf === undefined) {\n return false;\n }\n if (HTML_SANITIZER_LEAF_RE.test(leaf)) {\n return true;\n }\n return leaf === \"sanitize\" && /^dompurify$/iu.test(parts.at(-2) ?? \"\");\n};\n\nconst isSanitizerResult = (node: unknown): boolean => {\n const expression = unwrapExpression(node);\n if (expression?.type !== \"MemberExpression\") {\n return false;\n }\n const property = memberPropertyName(expression);\n return (\n property !== null &&\n SANITIZER_RESULT_MEMBERS.has(property) &&\n isSanitizerCall(expression.object)\n );\n};\n\ntype Located = { loc: { start: { line: number } } };\n\nconst hasLocation = (node: unknown): node is Located =>\n typeof node === \"object\" &&\n node !== null &&\n \"loc\" in node &&\n typeof node.loc === \"object\" &&\n node.loc !== null &&\n \"start\" in node.loc &&\n typeof node.loc.start === \"object\" &&\n node.loc.start !== null &&\n \"line\" in node.loc.start &&\n typeof node.loc.start.line === \"number\";\n\n// A node without location data never matches a waiver line.\nconst startLine = (node: unknown): number =>\n hasLocation(node) ? node.loc.start.line : Number.NaN;\n\ntype WaiverComment = {\n value: string;\n loc: { end: { line: number } };\n};\n\nconst isWaiverComment = (value: unknown): value is WaiverComment =>\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n typeof value.value === \"string\" &&\n WAIVER_RE.test(value.value) &&\n \"loc\" in value &&\n typeof value.loc === \"object\" &&\n value.loc !== null;\n\nconst jsxAttributeName = (node: unknown): string | null =>\n isAstNode(node) &&\n node.type === \"JSXIdentifier\" &&\n typeof node.name === \"string\"\n ? node.name\n : null;\n\n// A value is proven safe by its own static shape, independent of comments.\nconst isProvenSafeValue = (\n node: unknown,\n sanitizerPolicy: SanitizerPolicy,\n): boolean => {\n const expression = unwrapExpression(node);\n if (expression === null) {\n return false;\n }\n if (isStringLiteral(expression)) {\n return true;\n }\n if (\n sanitizerPolicy === SANITIZER_POLICY.allowlist &&\n (isSanitizerCall(expression) || isSanitizerResult(expression))\n ) {\n return true;\n }\n return (\n expression.type === \"TemplateLiteral\" &&\n Array.isArray(expression.expressions) &&\n expression.expressions.every((entry) =>\n isProvenSafeValue(entry, sanitizerPolicy),\n )\n );\n};\n\n// The static key of an object-literal Property: `a`, `\"a\"`, `[\"a\"]`.\nconst objectPropertyKey = (property: unknown): string | null => {\n if (!isAstNode(property)) {\n return null;\n }\n if (property.computed === true) {\n return staticStringValue(property.key);\n }\n return getPropertyName(property.key);\n};\n\nconst isOpaqueProperty = (property: AstNode): boolean =>\n property.type === \"SpreadElement\" ||\n (property.type === \"Property\" &&\n property.computed === true &&\n objectPropertyKey(property) === null);\n\nconst objectProperties = (node: unknown): AstNode[] => {\n const expression = unwrapExpression(node);\n if (\n expression?.type !== \"ObjectExpression\" ||\n !Array.isArray(expression.properties)\n ) {\n return [];\n }\n const properties: AstNode[] = [];\n for (const property of expression.properties.filter(isAstNode)) {\n if (\n property.type === \"SpreadElement\" &&\n unwrapExpression(property.argument)?.type === \"ObjectExpression\"\n ) {\n properties.push(...objectProperties(property.argument));\n continue;\n }\n properties.push(property);\n }\n return properties;\n};\n\ntype AppliedArguments = LiteralArgumentResolution;\n\nconst appliedArgumentsFor = (args: unknown[]): AppliedArguments => {\n const applied = unwrapExpression(args.at(1));\n if (\n applied === null ||\n (applied.type === \"Literal\" && applied.value === null) ||\n isIdentifier(applied, \"undefined\")\n ) {\n return { status: \"known\", args: [] };\n }\n if (applied.type !== \"ArrayExpression\" || !Array.isArray(applied.elements)) {\n return { status: \"opaque\", args: [], spread: args.at(1), tail: [] };\n }\n return resolveLiteralArraySpreads(applied.elements);\n};\n\n// The arguments the invoked function receives: `f.call(thisArg, ...args)`\n// shifts them by one; `f.apply(thisArg, [...])` forwards a literal array.\nconst invokedArguments = (call: unknown): AppliedArguments => {\n if (!isAstNode(call)) {\n return { status: \"known\", args: [] };\n }\n const rawArguments = Array.isArray(call.arguments) ? call.arguments : [];\n const resolved = resolveLiteralArraySpreads(rawArguments);\n const callee = unwrapExpression(call.callee);\n if (callee?.type !== \"MemberExpression\") return resolved;\n const method = memberPropertyName(callee);\n if (method === \"call\") {\n return { ...resolved, args: resolved.args.slice(1) };\n }\n if (method !== \"apply\") return resolved;\n if (resolved.status === \"opaque\") {\n if (resolved.args.length >= 2) return appliedArgumentsFor(resolved.args);\n return { ...resolved, args: [], tail: [] };\n }\n return appliedArgumentsFor(resolved.args);\n};\n\nconst plugin: Plugin = eslintCompatPlugin({\n meta: { name: \"no-unsafe-inner-html\" },\n rules: {\n \"no-unsafe-inner-html\": {\n meta: {\n type: \"problem\",\n schema: [\n {\n type: \"object\",\n properties: {\n sanitizerPolicy: {\n type: \"string\",\n enum: SANITIZER_POLICY_VALUES,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n unsafeInnerHtml:\n \"Dynamic HTML injected into the DOM must be static, proven by \" +\n \"the configured sanitizer policy, or have an adjacent \" +\n \"`// safe-html: <provenance>` comment naming the trusted source. \" +\n \"Function names outside the allowlist are not proof because a \" +\n \"local identity function can shadow them.\",\n unsafeInnerHtmlSpread:\n \"Do not spread an object in dangerouslySetInnerHTML. Keep \" +\n \"`__html` inline so this rule can prove the HTML value is \" +\n \"sanitized or escaped.\",\n unsafeInnerHtmlComputedKey:\n \"Do not use an unresolved computed key in \" +\n \"dangerouslySetInnerHTML. Write an explicit `__html` property \" +\n \"so this rule can \" +\n \"prove the HTML value is sanitized or escaped.\",\n },\n },\n createOnce(context) {\n type BindingOptions = {\n node: unknown;\n scope: Scope;\n seen: Set<Variable>;\n };\n type BindingSource = {\n kind: \"expression\" | \"iteration\";\n node: AstNode | null;\n scope: Scope;\n };\n // All document, element and collection checks share one stable-binding path.\n const resolveStableBinding = ({\n node,\n scope,\n seen,\n }: BindingOptions): BindingSource | null => {\n let target = unwrapExpression(node);\n while (isIdentifier(target)) {\n let current: Scope | null = scope;\n let variable: Variable | undefined;\n while (current !== null) {\n variable = current.set.get(target.name);\n if (variable !== undefined) break;\n current = current.upper;\n }\n if (variable === undefined || variable.defs.length === 0) {\n return { kind: \"expression\", node: target, scope };\n }\n if (seen.has(variable)) return null;\n seen.add(variable);\n const definition = variable.defs.at(0);\n // A never-reassigned class or function declaration holds a\n // function, which is neither an element nor a document.\n if (\n variable.defs.length === 1 &&\n (definition?.type === \"ClassName\" ||\n definition?.type === \"FunctionName\") &&\n (definition.node.type === \"ClassDeclaration\" ||\n definition.node.type === \"FunctionDeclaration\") &&\n !variable.references.some((reference) => reference.isWrite())\n ) {\n return {\n kind: \"expression\",\n node: unwrapExpression(definition.node),\n scope,\n };\n }\n if (\n variable.defs.length !== 1 ||\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n variable.references.some(\n (reference) => reference.isWrite() && !reference.init,\n )\n ) {\n return null;\n }\n const declarator = definition.node;\n if (declarator.init !== null) {\n target = unwrapExpression(declarator.init);\n scope = context.sourceCode.getScope(declarator);\n continue;\n }\n const declaration = declarator.parent;\n if (declaration.type !== \"VariableDeclaration\") return null;\n const loop = declaration.parent;\n if (loop.type !== \"ForOfStatement\" || loop.left !== declaration) {\n return null;\n }\n return {\n kind: \"iteration\",\n node: unwrapExpression(loop.right),\n scope: context.sourceCode.getScope(loop.right),\n };\n }\n return { kind: \"expression\", node: target, scope };\n };\n const isKnownNonEmptyNamespace = (\n namespace: unknown,\n scope: Scope,\n ): boolean => {\n const source = resolveStableBinding({\n node: namespace,\n scope,\n seen: new Set<Variable>(),\n });\n if (source?.kind !== \"expression\") return false;\n const text = staticStringValue(source.node);\n // DOM normalizes the empty namespace to null. Unknowns stay checked.\n if (text !== null) return text !== \"\";\n if (source.node?.type !== \"Literal\") return false;\n const { value } = source.node;\n return (\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n );\n };\n\n const variableFor = (\n identifier: { name: string },\n initialScope: Scope,\n ): Variable | undefined => {\n let current: Scope | null = initialScope;\n while (current !== null) {\n const variable = current.set.get(identifier.name);\n if (variable !== undefined) return variable;\n current = current.upper;\n }\n return undefined;\n };\n const isKnownNonDocumentReceiver = (\n node: unknown,\n scope: Scope,\n ): boolean => {\n const isUnshadowedGlobal = (\n identifier: unknown,\n name: string,\n ): boolean =>\n isIdentifier(identifier, name) &&\n variableFor(identifier, scope) === undefined;\n const isFileSystemImport = (identifier: unknown): boolean => {\n if (!isIdentifier(identifier)) return false;\n const variable = variableFor(identifier, scope);\n if (variable?.defs.length !== 1) return false;\n const definition = variable.defs.at(0);\n return (\n definition?.type === \"ImportBinding\" &&\n definition.parent?.type === \"ImportDeclaration\" &&\n FILE_SYSTEM_MODULES.has(definition.parent.source.value)\n );\n };\n // A const bound once to a child process factory call: a node\n // child_process import or the unshadowed Bun.spawn.\n const isChildProcess = (identifier: unknown): boolean => {\n if (!isIdentifier(identifier)) return false;\n const variable = variableFor(identifier, scope);\n const definition = variable?.defs.at(0);\n if (\n variable?.defs.length !== 1 ||\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n definition.node.parent.type !== \"VariableDeclaration\" ||\n definition.node.parent.kind !== \"const\"\n )\n return false;\n const init = unwrapExpression(definition.node.init);\n if (init?.type !== \"CallExpression\") return false;\n const callee = unwrapExpression(init.callee);\n if (callee?.type === \"MemberExpression\")\n return (\n memberPropertyName(callee) === \"spawn\" &&\n isUnshadowedGlobal(unwrapExpression(callee.object), \"Bun\")\n );\n if (!isIdentifier(callee)) return false;\n const factory = variableFor(callee, scope);\n const binding = factory?.defs.at(0);\n return (\n factory?.defs.length === 1 &&\n binding?.type === \"ImportBinding\" &&\n binding.node.type === \"ImportSpecifier\" &&\n binding.node.imported.type === \"Identifier\" &&\n CHILD_PROCESS_FACTORIES.has(binding.node.imported.name) &&\n binding.parent?.type === \"ImportDeclaration\" &&\n CHILD_PROCESS_MODULES.has(binding.parent.source.value)\n );\n };\n const root = unwrapExpression(node);\n if (isUnshadowedGlobal(root, \"Bun\") || isFileSystemImport(root)) {\n return true;\n }\n if (root?.type !== \"MemberExpression\") return false;\n const stream = memberPropertyName(root);\n const owner = unwrapExpression(root.object);\n return (\n ((stream === \"stdout\" || stream === \"stderr\") &&\n isUnshadowedGlobal(owner, \"process\")) ||\n (stream === \"stdin\" && isChildProcess(owner))\n );\n };\n const isDocumentReceiver = (node: unknown, scope: Scope): boolean => {\n if (isKnownNonDocumentReceiver(node, scope)) return false;\n const source = resolveStableBinding({\n node,\n scope,\n seen: new Set<Variable>(),\n });\n if (source === null || source.kind !== \"expression\") return true;\n const receiver = source.node;\n if (isIdentifier(receiver, \"document\")) return true;\n if (receiver?.type !== \"MemberExpression\") return false;\n const name = memberPropertyName(receiver);\n return name !== null && DOCUMENT_MEMBERS.has(name);\n };\n\n const isDocumentSinkReceiver = (\n node: unknown,\n scope: Scope,\n ): boolean => {\n if (isKnownNonDocumentReceiver(node, scope)) return false;\n const receiver = unwrapExpression(node);\n if (!isIdentifier(receiver)) return true;\n let current: Scope | null = scope;\n let variable: Variable | undefined;\n while (current !== null) {\n variable = current.set.get(receiver.name);\n if (variable !== undefined) break;\n current = current.upper;\n }\n if (variable === undefined || variable.defs.length !== 1) return true;\n const definition = variable.defs.at(0);\n if (\n definition?.type !== \"Variable\" ||\n definition.node.type !== \"VariableDeclarator\" ||\n definition.node.id.type !== \"Identifier\" ||\n definition.node.init === null ||\n unwrapExpression(definition.node.init)?.type !==\n \"ObjectExpression\" ||\n definition.node.parent.type !== \"VariableDeclaration\" ||\n definition.node.parent.kind !== \"const\" ||\n variable.scope.variableScope !== scope.variableScope ||\n variable.references.some(\n (reference) => reference.isWrite() && !reference.init,\n )\n ) {\n return true;\n }\n return false;\n };\n type DomTargetOptions = {\n node: unknown;\n scope: Scope;\n seen?: Set<Variable>;\n kind?: \"element\" | \"collection\";\n };\n const isKnownDomTarget = ({\n node,\n scope,\n seen = new Set<Variable>(),\n kind = \"element\",\n }: DomTargetOptions): boolean => {\n const source = resolveStableBinding({ node, scope, seen });\n // An unstable binding may have been reassigned to a DOM target. Fail\n // closed unless the resolver can prove a stable non-DOM value.\n if (source === null) return true;\n if (source.kind === \"iteration\") {\n return (\n kind === \"element\" &&\n isKnownDomTarget({\n node: source.node,\n scope: source.scope,\n seen,\n kind: \"collection\",\n })\n );\n }\n const target = source.node;\n scope = source.scope;\n const hasProducerReceiver = (\n receiver: unknown,\n producer: DomElementProducer,\n ): boolean => {\n if (\n producer.receiver !== \"element\" &&\n isDocumentReceiver(receiver, scope)\n ) {\n return true;\n }\n return (\n producer.receiver !== \"document\" &&\n isKnownDomTarget({ node: receiver, scope, seen })\n );\n };\n const isElementCollection = (collection: unknown): boolean =>\n isKnownDomTarget({\n node: collection,\n scope,\n seen,\n kind: \"collection\",\n });\n if (target?.type === \"MemberExpression\") {\n const property = memberPropertyName(target);\n const producer = (\n DOM_ELEMENT_PRODUCERS satisfies readonly DomElementProducer[]\n ).find(\n (entry) =>\n entry.kind ===\n (kind === \"collection\"\n ? \"collection-property\"\n : \"property\") && entry.name === property,\n );\n if (producer !== undefined) {\n return hasProducerReceiver(target.object, producer);\n }\n const index = unwrapExpression(target.property);\n if (\n kind === \"element\" &&\n target.computed === true &&\n index?.type === \"Literal\" &&\n typeof index.value === \"number\" &&\n Number.isInteger(index.value) &&\n index.value >= 0\n ) {\n return isElementCollection(target.object);\n }\n }\n if (target?.type === \"CallExpression\") {\n const callee = invokedCallee(target);\n if (callee?.type !== \"MemberExpression\") return false;\n const method = memberPropertyName(callee);\n if (\n kind === \"element\" &&\n method === \"item\" &&\n isElementCollection(callee.object)\n ) {\n return true;\n }\n const producer = DOM_ELEMENT_PRODUCERS.find(\n (entry) =>\n entry.kind ===\n (kind === \"collection\" ? \"collection\" : \"method\") &&\n entry.name === method,\n );\n return (\n producer !== undefined &&\n hasProducerReceiver(callee.object, producer)\n );\n }\n return kind === \"element\" && isDocumentReceiver(target, scope);\n };\n\n let sanitizerPolicy: SanitizerPolicy = SANITIZER_POLICY.allowlist;\n // Associate waivers after visiting the file, so source position decides\n // the first covered sink even when AST visitors inspect values out of order.\n const waiverLines = new Set<number>();\n type SinkObservation = {\n node: AstNode;\n kind:\n | \"safe\"\n | \"unsafe\"\n | \"opaque-payload-spread\"\n | \"opaque-payload-computed-key\";\n };\n const sinks: SinkObservation[] = [];\n const observeSink = (\n node: unknown,\n kind: SinkObservation[\"kind\"],\n ): void => {\n if (isAstNode(node)) sinks.push({ node, kind });\n };\n const messageIdFor = (kind: SinkObservation[\"kind\"]) => {\n if (kind === \"opaque-payload-spread\") {\n return \"unsafeInnerHtmlSpread\";\n }\n if (kind === \"opaque-payload-computed-key\") {\n return \"unsafeInnerHtmlComputedKey\";\n }\n return \"unsafeInnerHtml\";\n };\n\n const consumeWaiver = (node: unknown): boolean => {\n const line = startLine(node) - 1;\n if (!waiverLines.has(line)) {\n return false;\n }\n waiverLines.delete(line);\n return true;\n };\n\n const reportIfUnsafe = (node: unknown): void => {\n observeSink(\n node,\n isProvenSafeValue(node, sanitizerPolicy) ? \"safe\" : \"unsafe\",\n );\n };\n\n // The value of a `dangerouslySetInnerHTML` prop: an inline object has\n // its `__html` checked and its spreads rejected; anything else is a\n // hoisted payload whose HTML this rule cannot see.\n const checkDangerousPayload = (\n value: unknown,\n htmlKey: string,\n ): void => {\n const expression = unwrapExpression(value);\n if (expression?.type !== \"ObjectExpression\") {\n reportIfUnsafe(value);\n return;\n }\n for (const property of objectProperties(expression)) {\n if (isOpaqueProperty(property)) {\n observeSink(\n property,\n property.type === \"SpreadElement\"\n ? \"opaque-payload-spread\"\n : \"opaque-payload-computed-key\",\n );\n continue;\n }\n if (\n property.type === \"Property\" &&\n objectPropertyKey(property) === htmlKey\n ) {\n reportIfUnsafe(property.value);\n }\n }\n };\n\n const checkReactHtmlProp = (\n prop: ReactHtmlProp,\n value: unknown,\n ): void => {\n switch (prop.kind) {\n case \"payload\":\n checkDangerousPayload(value, prop.htmlKey);\n return;\n case \"value\":\n reportIfUnsafe(value);\n return;\n default: {\n const exhaustive: never = prop;\n throw new Error(`Unknown React HTML prop: ${String(exhaustive)}`);\n }\n }\n };\n\n const checkReactProps = (value: unknown): void => {\n for (const property of objectProperties(value)) {\n if (property.type !== \"Property\") continue;\n const key = objectPropertyKey(property);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === key);\n // Payload properties are checked once by the Property visitor.\n if (prop?.kind === \"value\")\n checkReactHtmlProp(prop, property.value);\n }\n };\n\n const checkHtmlPropertySources = (\n sources: unknown[],\n domTarget: boolean,\n ): void => {\n for (const source of sources) {\n const expression = unwrapExpression(source);\n // Each branch of a conditional or logical expression may be the\n // value Object.assign copies from; the condition itself is not,\n // and the left side of `&&` is copied only when falsy, so never\n // as an object.\n if (expression?.type === \"ConditionalExpression\") {\n checkHtmlPropertySources(\n [expression.consequent, expression.alternate],\n domTarget,\n );\n continue;\n }\n // Object.assign skips null and undefined sources.\n if (\n (expression?.type === \"Literal\" && expression.value === null) ||\n isIdentifier(expression, \"undefined\")\n ) {\n continue;\n }\n if (expression?.type === \"LogicalExpression\") {\n checkHtmlPropertySources(\n expression.operator === \"&&\"\n ? [expression.right]\n : [expression.left, expression.right],\n domTarget,\n );\n continue;\n }\n if (expression?.type !== \"ObjectExpression\") {\n if (domTarget) {\n reportIfUnsafe(source);\n }\n continue;\n }\n for (const property of objectProperties(source)) {\n if (isOpaqueProperty(property)) {\n if (domTarget) {\n reportIfUnsafe(property);\n }\n continue;\n }\n const key =\n property.type === \"Property\"\n ? objectPropertyKey(property)\n : null;\n if (key !== null && HTML_PROPERTIES.has(key)) {\n reportIfUnsafe(property.value);\n }\n }\n }\n };\n\n return {\n before() {\n sanitizerPolicy = sanitizerPolicyFrom(context.options.at(0));\n waiverLines.clear();\n sinks.length = 0;\n },\n \"Program:exit\"() {\n sinks.sort(\n (left, right) => left.node.range[0] - right.node.range[0],\n );\n for (const { node, kind } of sinks) {\n const waived = consumeWaiver(node);\n if (kind === \"safe\" || (kind === \"unsafe\" && waived)) continue;\n context.report({\n node,\n messageId: messageIdFor(kind),\n });\n }\n sinks.length = 0;\n },\n Program(node) {\n const comments: unknown[] = Array.isArray(node.comments)\n ? node.comments\n : [];\n for (const comment of comments) {\n if (isWaiverComment(comment)) {\n waiverLines.add(comment.loc.end.line);\n }\n }\n },\n\n JSXAttribute(node) {\n const name = jsxAttributeName(node.name);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === name);\n if (prop === undefined) return;\n const value = unwrapExpression(node.value);\n checkReactHtmlProp(\n prop,\n value?.type === \"JSXExpressionContainer\"\n ? value.expression\n : value,\n );\n },\n\n JSXSpreadAttribute(node) {\n checkReactProps(node.argument);\n },\n\n // Payload objects remain checked when hoisted or spread into JSX.\n // Direct value props use the JSX and factory props contexts.\n Property(node) {\n const key = objectPropertyKey(node);\n const prop = REACT_HTML_PROPS.find((entry) => entry.name === key);\n if (prop?.kind !== \"payload\") return;\n const container = node.parent;\n if (isAstNode(container) && container.type === \"ObjectExpression\") {\n checkReactHtmlProp(prop, node.value);\n }\n },\n\n AssignmentExpression(node) {\n const target = unwrapExpression(node.left);\n if (target?.type !== \"MemberExpression\") {\n return;\n }\n const name = memberPropertyName(target);\n if (name !== null && HTML_PROPERTIES.has(name)) {\n reportIfUnsafe(node.right);\n }\n },\n\n CallExpression(node) {\n const call: unknown = node;\n const callee = isAstNode(call) ? invokedCallee(call) : null;\n const invoked = invokedArguments(node);\n const factory = staticCalleeName(callee);\n if (factory !== null && REACT_ELEMENT_FACTORIES.has(factory)) {\n checkReactProps(invoked.args.at(1));\n return;\n }\n if (callee?.type !== \"MemberExpression\") {\n return;\n }\n const method = memberPropertyName(callee);\n if (method === null) {\n return;\n }\n if (HTML_FIRST_ARGUMENT_METHODS.has(method)) {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n reportIfUnsafe(invoked.args.at(0));\n return;\n }\n if (method === \"insertAdjacentHTML\") {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n reportIfUnsafe(invoked.args.at(1));\n return;\n }\n const attributeSink = HTML_ATTRIBUTE_SINKS.find(\n (entry) => entry.name === method,\n );\n if (attributeSink !== undefined) {\n if (\n attributeSink.namespaceIndex !== null &&\n isKnownNonEmptyNamespace(\n invoked.args.at(attributeSink.namespaceIndex),\n context.sourceCode.getScope(node),\n )\n ) {\n return;\n }\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n const attribute = staticStringValue(\n invoked.args.at(attributeSink.nameIndex),\n );\n if (attribute?.toLowerCase() === \"srcdoc\") {\n reportIfUnsafe(invoked.args.at(attributeSink.valueIndex));\n }\n return;\n }\n if (\n DOCUMENT_WRITE_METHODS.has(method) &&\n isDocumentSinkReceiver(\n callee.object,\n context.sourceCode.getScope(node),\n )\n ) {\n if (invoked.status === \"opaque\") {\n reportIfUnsafe(node);\n return;\n }\n observeSink(\n node,\n invoked.args.every((argument) =>\n isProvenSafeValue(argument, sanitizerPolicy),\n )\n ? \"safe\"\n : \"unsafe\",\n );\n return;\n }\n if (isIdentifier(callee.object, \"Object\") && method === \"assign\") {\n const domTarget = isKnownDomTarget({\n node: invoked.args.at(0),\n scope: context.sourceCode.getScope(node),\n });\n checkHtmlPropertySources(\n [\n ...invoked.args.slice(1),\n ...(invoked.status === \"opaque\" ? invoked.tail : []),\n ],\n domTarget,\n );\n if (invoked.status === \"opaque\" && domTarget) {\n reportIfUnsafe(invoked.spread);\n }\n }\n },\n };\n },\n },\n },\n});\n\nexport default plugin;\n"],"mappings":";;;AA2DA,MAAa,wBAAwB;CACnC;EAAE,MAAM;EAAQ,MAAM;EAAY,UAAU;CAAW;CACvD;EAAE,MAAM;EAAQ,MAAM;EAAY,UAAU;CAAW;CACvD;EAAE,MAAM;EAAmB,MAAM;EAAY,U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,OAAO,CAAC,CACpD,GACA,SACF;MACA,IAAI,QAAQ,WAAW,YAAY,WACjC,eAAe,QAAQ,MAAM;KAEjC;IACF;GACF;EACF;CACF,EACF;AACF,CAAC"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
const require_test_rule_utils = require("./test-rule-utils.cjs");
|
|
6
6
|
//#region src/no-unseeded-random-in-tests.ts
|
|
7
|
-
|
|
7
|
+
const plugin = require_test_rule_utils.testOnlyPlugin("no-unseeded-random-in-tests", "noUnseededRandom", "Use @stll/test-kit's createSeededRandom or testSeed for test input.", (report, getScope) => {
|
|
8
8
|
const resolveBinding = require_test_rule_utils.createBindingResolver(getScope);
|
|
9
9
|
const isGlobal = (value, name) => require_test_rule_utils.isNode(value) && resolveBinding(value).type === "global" && require_test_rule_utils.identifierName(value) === name;
|
|
10
10
|
const isRandomMember = (value) => {
|
|
@@ -20,6 +20,6 @@ var no_unseeded_random_in_tests_default = require_test_rule_utils.testOnlyPlugin
|
|
|
20
20
|
} };
|
|
21
21
|
});
|
|
22
22
|
//#endregion
|
|
23
|
-
exports.default =
|
|
23
|
+
exports.default = plugin;
|
|
24
24
|
|
|
25
25
|
//# sourceMappingURL=no-unseeded-random-in-tests.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unseeded-random-in-tests.cjs","names":["testOnlyPlugin","createBindingResolver","isNode","identifierName","propertyName"],"sources":["../src/no-unseeded-random-in-tests.ts"],"sourcesContent":["import {\n createBindingResolver,\n identifierName,\n isNode,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\
|
|
1
|
+
{"version":3,"file":"no-unseeded-random-in-tests.cjs","names":["testOnlyPlugin","createBindingResolver","isNode","identifierName","propertyName"],"sources":["../src/no-unseeded-random-in-tests.ts"],"sourcesContent":["import type { Plugin } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst plugin: Plugin = testOnlyPlugin(\n \"no-unseeded-random-in-tests\",\n \"noUnseededRandom\",\n \"Use @stll/test-kit's createSeededRandom or testSeed for test input.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n const isGlobal = (value: unknown, name: string): boolean =>\n isNode(value) &&\n resolveBinding(value).type === \"global\" &&\n identifierName(value) === name;\n const isRandomMember = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"Identifier\") {\n const binding = resolveBinding(value);\n return binding.type === \"const\" && isRandomMember(binding.initializer);\n }\n return (\n value.type === \"MemberExpression\" &&\n ((propertyName(value.property) === \"random\" &&\n isGlobal(value.object, \"Math\")) ||\n (propertyName(value.property) === \"getRandomValues\" &&\n isGlobal(value.object, \"crypto\")))\n );\n };\n return {\n CallExpression(node) {\n if (isRandomMember(node.callee)) report(node);\n },\n };\n },\n);\n\nexport default plugin;\n"],"mappings":";;;;;;AAUA,MAAM,SAAiBA,wBAAAA,eACrB,+BACA,oBACA,wEACC,QAAQ,aAAa;CACpB,MAAM,iBAAiBC,wBAAAA,sBAAsB,QAAQ;CACrD,MAAM,YAAY,OAAgB,SAChCC,wBAAAA,OAAO,KAAK,KACZ,eAAe,KAAK,CAAC,CAAC,SAAS,YAC/BC,wBAAAA,eAAe,KAAK,MAAM;CAC5B,MAAM,kBAAkB,UAA4B;EAClD,IAAI,CAACD,wBAAAA,OAAO,KAAK,GAAG,OAAO;EAC3B,IAAI,MAAM,SAAS,cAAc;GAC/B,MAAM,UAAU,eAAe,KAAK;GACpC,OAAO,QAAQ,SAAS,WAAW,eAAe,QAAQ,WAAW;EACvE;EACA,OACE,MAAM,SAAS,uBACbE,wBAAAA,aAAa,MAAM,QAAQ,MAAM,YACjC,SAAS,MAAM,QAAQ,MAAM,KAC5BA,wBAAAA,aAAa,MAAM,QAAQ,MAAM,qBAChC,SAAS,MAAM,QAAQ,QAAQ;CAEvC;CACA,OAAO,EACL,eAAe,MAAM;EACnB,IAAI,eAAe,KAAK,MAAM,GAAG,OAAO,IAAI;CAC9C,EACF;AACF,CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { Plugin } from "@oxlint/plugins";
|
|
1
2
|
//#region src/no-unseeded-random-in-tests.d.ts
|
|
2
|
-
declare const
|
|
3
|
-
export =
|
|
3
|
+
declare const plugin: Plugin;
|
|
4
|
+
export = plugin;
|
|
4
5
|
//# sourceMappingURL=no-unseeded-random-in-tests.d.cts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Plugin } from "@oxlint/plugins";
|
|
1
2
|
//#region src/no-unseeded-random-in-tests.d.ts
|
|
2
|
-
declare const
|
|
3
|
+
declare const plugin: Plugin;
|
|
3
4
|
//#endregion
|
|
4
|
-
export {
|
|
5
|
+
export { plugin as default };
|
|
5
6
|
//# sourceMappingURL=no-unseeded-random-in-tests.d.mts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as testOnlyPlugin, i as propertyName, n as identifierName, r as isNode, t as createBindingResolver } from "./test-rule-utils.mjs";
|
|
2
2
|
//#region src/no-unseeded-random-in-tests.ts
|
|
3
|
-
|
|
3
|
+
const plugin = testOnlyPlugin("no-unseeded-random-in-tests", "noUnseededRandom", "Use @stll/test-kit's createSeededRandom or testSeed for test input.", (report, getScope) => {
|
|
4
4
|
const resolveBinding = createBindingResolver(getScope);
|
|
5
5
|
const isGlobal = (value, name) => isNode(value) && resolveBinding(value).type === "global" && identifierName(value) === name;
|
|
6
6
|
const isRandomMember = (value) => {
|
|
@@ -16,6 +16,6 @@ var no_unseeded_random_in_tests_default = testOnlyPlugin("no-unseeded-random-in-
|
|
|
16
16
|
} };
|
|
17
17
|
});
|
|
18
18
|
//#endregion
|
|
19
|
-
export {
|
|
19
|
+
export { plugin as default };
|
|
20
20
|
|
|
21
21
|
//# sourceMappingURL=no-unseeded-random-in-tests.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unseeded-random-in-tests.mjs","names":[],"sources":["../src/no-unseeded-random-in-tests.ts"],"sourcesContent":["import {\n createBindingResolver,\n identifierName,\n isNode,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\
|
|
1
|
+
{"version":3,"file":"no-unseeded-random-in-tests.mjs","names":[],"sources":["../src/no-unseeded-random-in-tests.ts"],"sourcesContent":["import type { Plugin } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst plugin: Plugin = testOnlyPlugin(\n \"no-unseeded-random-in-tests\",\n \"noUnseededRandom\",\n \"Use @stll/test-kit's createSeededRandom or testSeed for test input.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n const isGlobal = (value: unknown, name: string): boolean =>\n isNode(value) &&\n resolveBinding(value).type === \"global\" &&\n identifierName(value) === name;\n const isRandomMember = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"Identifier\") {\n const binding = resolveBinding(value);\n return binding.type === \"const\" && isRandomMember(binding.initializer);\n }\n return (\n value.type === \"MemberExpression\" &&\n ((propertyName(value.property) === \"random\" &&\n isGlobal(value.object, \"Math\")) ||\n (propertyName(value.property) === \"getRandomValues\" &&\n isGlobal(value.object, \"crypto\")))\n );\n };\n return {\n CallExpression(node) {\n if (isRandomMember(node.callee)) report(node);\n },\n };\n },\n);\n\nexport default plugin;\n"],"mappings":";;AAUA,MAAM,SAAiB,eACrB,+BACA,oBACA,wEACC,QAAQ,aAAa;CACpB,MAAM,iBAAiB,sBAAsB,QAAQ;CACrD,MAAM,YAAY,OAAgB,SAChC,OAAO,KAAK,KACZ,eAAe,KAAK,CAAC,CAAC,SAAS,YAC/B,eAAe,KAAK,MAAM;CAC5B,MAAM,kBAAkB,UAA4B;EAClD,IAAI,CAAC,OAAO,KAAK,GAAG,OAAO;EAC3B,IAAI,MAAM,SAAS,cAAc;GAC/B,MAAM,UAAU,eAAe,KAAK;GACpC,OAAO,QAAQ,SAAS,WAAW,eAAe,QAAQ,WAAW;EACvE;EACA,OACE,MAAM,SAAS,uBACb,aAAa,MAAM,QAAQ,MAAM,YACjC,SAAS,MAAM,QAAQ,MAAM,KAC5B,aAAa,MAAM,QAAQ,MAAM,qBAChC,SAAS,MAAM,QAAQ,QAAQ;CAEvC;CACA,OAAO,EACL,eAAe,MAAM;EACnB,IAAI,eAAe,KAAK,MAAM,GAAG,OAAO,IAAI;CAC9C,EACF;AACF,CACF"}
|
|
@@ -46,7 +46,7 @@ const enclosingFunction = (node) => {
|
|
|
46
46
|
}
|
|
47
47
|
return null;
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
const plugin = require_test_rule_utils.testOnlyPlugin("no-wall-clock-bound", "noWallClockBound", "A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.", (report, getScope) => {
|
|
50
50
|
const resolveBinding = require_test_rule_utils.createBindingResolver(getScope);
|
|
51
51
|
const isGlobalMember = (node, objectName, member) => {
|
|
52
52
|
if (node.type !== "MemberExpression") return false;
|
|
@@ -148,6 +148,6 @@ var no_wall_clock_bound_default = require_test_rule_utils.testOnlyPlugin("no-wal
|
|
|
148
148
|
} };
|
|
149
149
|
});
|
|
150
150
|
//#endregion
|
|
151
|
-
exports.default =
|
|
151
|
+
exports.default = plugin;
|
|
152
152
|
|
|
153
153
|
//# sourceMappingURL=no-wall-clock-bound.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-wall-clock-bound.cjs","names":["isNode","testOnlyPlugin","createBindingResolver","propertyName","identifierName"],"sources":["../src/no-wall-clock-bound.ts"],"sourcesContent":["import type { Scope } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n type Node,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst timerModules = new Set([\n \"node:timers/promises\",\n \"timers/promises\",\n \"@stll/test-kit\",\n]);\nconst timerHelpers = new Set([\"delay\", \"setTimeout\", \"sleep\"]);\nconst testModules = new Set([\"@jest/globals\", \"bun:test\", \"vitest\"]);\nconst functionTypes = new Set([\n \"ArrowFunctionExpression\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n]);\nconst matcherModifiers = new Set([\"not\", \"rejects\", \"resolves\"]);\n\nconst isVariableReference = (identifier: Node): boolean => {\n const parent = identifier.parent;\n if (!isNode(parent)) return true;\n if (\n parent.type === \"MemberExpression\" &&\n parent.property === identifier &&\n parent.computed !== true\n )\n return false;\n if (\n (parent.type === \"Property\" ||\n parent.type === \"MethodDefinition\" ||\n parent.type === \"PropertyDefinition\") &&\n parent.key === identifier &&\n parent.computed !== true &&\n parent.value !== identifier\n )\n return false;\n if (\n (parent.type === \"LabeledStatement\" ||\n parent.type === \"BreakStatement\" ||\n parent.type === \"ContinueStatement\") &&\n parent.label === identifier\n )\n return false;\n if (\n (parent.type === \"VariableDeclarator\" ||\n parent.type === \"FunctionDeclaration\" ||\n parent.type === \"FunctionExpression\" ||\n parent.type === \"ClassDeclaration\" ||\n parent.type === \"ClassExpression\") &&\n parent.id === identifier\n )\n return false;\n return true;\n};\n\nconst enclosingFunction = (node: Node): Node | null => {\n let current = node.parent;\n while (isNode(current)) {\n if (functionTypes.has(current.type)) return current;\n current = current.parent;\n }\n return null;\n};\n\nexport default testOnlyPlugin(\n \"no-wall-clock-bound\",\n \"noWallClockBound\",\n \"A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n\n const isGlobalMember = (\n node: Node,\n objectName: string,\n member: string,\n ): boolean => {\n if (node.type !== \"MemberExpression\") return false;\n if (propertyName(node.property) !== member || !isNode(node.object))\n return false;\n const binding = resolveBinding(node.object);\n return binding.type === \"global\" && binding.name === objectName;\n };\n\n const isClockRead = (value: unknown): boolean => {\n if (!isNode(value) || value.type !== \"CallExpression\") return false;\n if (!isNode(value.callee)) return false;\n if (\n isGlobalMember(value.callee, \"performance\", \"now\") ||\n isGlobalMember(value.callee, \"Date\", \"now\") ||\n isGlobalMember(value.callee, \"Bun\", \"nanoseconds\")\n )\n return true;\n const callee = value.callee;\n return (\n callee.type === \"MemberExpression\" &&\n propertyName(callee.property) === \"bigint\" &&\n isNode(callee.object) &&\n isGlobalMember(callee.object, \"process\", \"hrtime\")\n );\n };\n\n const constInitializerInSameFunction = (\n identifier: Node,\n use: Node,\n ): Node | null => {\n const name = identifierName(identifier);\n if (name === null) return null;\n let scope: Scope | null = getScope(identifier);\n while (scope !== null) {\n const variable = scope.set.get(name);\n if (variable === undefined) {\n scope = scope.upper;\n continue;\n }\n const definition = variable.defs.at(0);\n if (definition?.type !== \"Variable\") return null;\n const declarator = definition.node as unknown;\n if (\n !isNode(declarator) ||\n !isNode(declarator.parent) ||\n declarator.parent.type !== \"VariableDeclaration\" ||\n declarator.parent.kind !== \"const\" ||\n !isNode(declarator.init) ||\n enclosingFunction(declarator) !== enclosingFunction(use)\n )\n return null;\n return declarator.init;\n }\n return null;\n };\n\n const containsClockRead = (\n value: unknown,\n use: Node,\n followIdentifier: boolean,\n visitedIdentifiers = new Set<Node>(),\n ): boolean => {\n if (Array.isArray(value))\n return value.some((child) =>\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n if (!isNode(value)) return false;\n if (isClockRead(value)) return true;\n if (\n followIdentifier &&\n value.type === \"Identifier\" &&\n isVariableReference(value)\n ) {\n if (visitedIdentifiers.has(value)) return false;\n visitedIdentifiers.add(value);\n const initializer = constInitializerInSameFunction(value, use);\n if (\n initializer !== null &&\n containsClockRead(initializer, use, true, visitedIdentifiers)\n )\n return true;\n }\n return Object.values(value).some(\n (child) =>\n child !== value.parent &&\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n };\n\n const matcherExpectCall = (value: unknown): Node | null => {\n let current = value;\n while (\n isNode(current) &&\n current.type === \"MemberExpression\" &&\n matcherModifiers.has(propertyName(current.property) ?? \"\")\n )\n current = current.object;\n return isNode(current) && current.type === \"CallExpression\"\n ? current\n : null;\n };\n\n const containsSetTimeout = (value: unknown): boolean => {\n if (Array.isArray(value)) return value.some(containsSetTimeout);\n if (!isNode(value)) return false;\n if (value.type === \"CallExpression\" && isNode(value.callee)) {\n const binding = resolveBinding(value.callee);\n if (binding.type === \"global\" && binding.name === \"setTimeout\")\n return true;\n }\n for (const child of Object.values(value)) {\n if (child === value.parent) continue;\n if (Array.isArray(child)) {\n if (child.some(containsSetTimeout)) return true;\n } else if (containsSetTimeout(child)) return true;\n }\n return false;\n };\n\n const isTimer = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"NewExpression\") {\n if (!isNode(value.callee)) return false;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"global\" &&\n binding.name === \"Promise\" &&\n containsSetTimeout(value.arguments)\n );\n }\n if (value.type !== \"CallExpression\" || !isNode(value.callee))\n return false;\n if (isGlobalMember(value.callee, \"Bun\", \"sleep\")) return true;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"import\" &&\n timerModules.has(binding.module) &&\n timerHelpers.has(binding.imported)\n );\n };\n\n const isTimerOrBoundTimer = (value: unknown, use: Node): boolean => {\n if (isTimer(value)) return true;\n if (!isNode(value) || value.type !== \"Identifier\") return false;\n const initializer = constInitializerInSameFunction(value, use);\n return initializer !== null && isTimer(initializer);\n };\n\n return {\n CallExpression(node) {\n if (!isNode(node.callee) || node.callee.type !== \"MemberExpression\")\n return;\n const member = propertyName(node.callee.property);\n if (member === \"race\" && isNode(node.callee.object)) {\n const binding = resolveBinding(node.callee.object);\n if (binding.type === \"global\" && binding.name === \"Promise\") {\n const firstArgument = Array.isArray(node.arguments)\n ? node.arguments.at(0)\n : null;\n if (\n isNode(firstArgument) &&\n firstArgument.type === \"ArrayExpression\" &&\n Array.isArray(firstArgument.elements) &&\n firstArgument.elements.some((element) =>\n isTimerOrBoundTimer(element, node),\n )\n )\n report(node);\n return;\n }\n }\n const expectCall = matcherExpectCall(node.callee.object);\n if (expectCall === null || !isNode(expectCall.callee)) return;\n const calleeBinding = resolveBinding(expectCall.callee);\n const isExpect =\n (calleeBinding.type === \"global\" &&\n calleeBinding.name === \"expect\") ||\n (calleeBinding.type === \"import\" &&\n calleeBinding.imported === \"expect\" &&\n testModules.has(calleeBinding.module));\n if (!isExpect) return;\n const assertionValues = [expectCall.arguments, node.arguments];\n if (containsClockRead(assertionValues, node, true)) report(node);\n },\n };\n },\n);\n"],"mappings":";;;;;;AAWA,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAS;CAAc;AAAO,CAAC;AAC7D,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAiB;CAAY;AAAQ,CAAC;AACnE,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;AACF,CAAC;AACD,MAAM,mCAAmB,IAAI,IAAI;CAAC;CAAO;CAAW;AAAU,CAAC;AAE/D,MAAM,uBAAuB,eAA8B;CACzD,MAAM,SAAS,WAAW;CAC1B,IAAI,CAACA,wBAAAA,OAAO,MAAM,GAAG,OAAO;CAC5B,IACE,OAAO,SAAS,sBAChB,OAAO,aAAa,cACpB,OAAO,aAAa,MAEpB,OAAO;CACT,KACG,OAAO,SAAS,cACf,OAAO,SAAS,sBAChB,OAAO,SAAS,yBAClB,OAAO,QAAQ,cACf,OAAO,aAAa,QACpB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,sBACf,OAAO,SAAS,oBAChB,OAAO,SAAS,wBAClB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,wBACf,OAAO,SAAS,yBAChB,OAAO,SAAS,wBAChB,OAAO,SAAS,sBAChB,OAAO,SAAS,sBAClB,OAAO,OAAO,YAEd,OAAO;CACT,OAAO;AACT;AAEA,MAAM,qBAAqB,SAA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,MAAM,cAAc,+BAA+B,OAAO,GAAG;EAC7D,OAAO,gBAAgB,QAAQ,QAAQ,WAAW;CACpD;CAEA,OAAO,EACL,eAAe,MAAM;EACnB,IAAI,CAACA,wBAAAA,OAAO,KAAK,MAAM,KAAK,KAAK,OAAO,SAAS,oBAC/C;EAEF,IADeG,wBAAAA,aAAa,KAAK,OAAO,QAC/B,MAAM,UAAUH,wBAAAA,OAAO,KAAK,OAAO,MAAM,GAAG;GACnD,MAAM,UAAU,eAAe,KAAK,OAAO,MAAM;GACjD,IAAI,QAAQ,SAAS,YAAY,QAAQ,SAAS,WAAW;IAC3D,MAAM,gBAAgB,MAAM,QAAQ,KAAK,SAAS,IAC9C,KAAK,UAAU,GAAG,CAAC,IACnB;IACJ,IACEA,wBAAAA,OAAO,aAAa,KACpB,cAAc,SAAS,qBACvB,MAAM,QAAQ,cAAc,QAAQ,KACpC,cAAc,SAAS,MAAM,YAC3B,oBAAoB,SAAS,IAAI,CACnC,GAEA,OAAO,IAAI;IACb;GACF;EACF;EACA,MAAM,aAAa,kBAAkB,KAAK,OAAO,MAAM;EACvD,IAAI,eAAe,QAAQ,CAACA,wBAAAA,OAAO,WAAW,MAAM,GAAG;EACvD,MAAM,gBAAgB,eAAe,WAAW,MAAM;EAOtD,IAAI,EALD,cAAc,SAAS,YACtB,cAAc,SAAS,YACxB,cAAc,SAAS,YACtB,cAAc,aAAa,YAC3B,YAAY,IAAI,cAAc,MAAM,IACzB;EACf,MAAM,kBAAkB,CAAC,WAAW,WAAW,KAAK,SAAS;EAC7D,IAAI,kBAAkB,iBAAiB,MAAM,IAAI,GAAG,OAAO,IAAI;CACjE,EACF;AACF,CACF"}
|
|
1
|
+
{"version":3,"file":"no-wall-clock-bound.cjs","names":["isNode","testOnlyPlugin","createBindingResolver","propertyName","identifierName"],"sources":["../src/no-wall-clock-bound.ts"],"sourcesContent":["import type { Plugin, Scope } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n type Node,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst timerModules = new Set([\n \"node:timers/promises\",\n \"timers/promises\",\n \"@stll/test-kit\",\n]);\nconst timerHelpers = new Set([\"delay\", \"setTimeout\", \"sleep\"]);\nconst testModules = new Set([\"@jest/globals\", \"bun:test\", \"vitest\"]);\nconst functionTypes = new Set([\n \"ArrowFunctionExpression\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n]);\nconst matcherModifiers = new Set([\"not\", \"rejects\", \"resolves\"]);\n\nconst isVariableReference = (identifier: Node): boolean => {\n const parent = identifier.parent;\n if (!isNode(parent)) return true;\n if (\n parent.type === \"MemberExpression\" &&\n parent.property === identifier &&\n parent.computed !== true\n )\n return false;\n if (\n (parent.type === \"Property\" ||\n parent.type === \"MethodDefinition\" ||\n parent.type === \"PropertyDefinition\") &&\n parent.key === identifier &&\n parent.computed !== true &&\n parent.value !== identifier\n )\n return false;\n if (\n (parent.type === \"LabeledStatement\" ||\n parent.type === \"BreakStatement\" ||\n parent.type === \"ContinueStatement\") &&\n parent.label === identifier\n )\n return false;\n if (\n (parent.type === \"VariableDeclarator\" ||\n parent.type === \"FunctionDeclaration\" ||\n parent.type === \"FunctionExpression\" ||\n parent.type === \"ClassDeclaration\" ||\n parent.type === \"ClassExpression\") &&\n parent.id === identifier\n )\n return false;\n return true;\n};\n\nconst enclosingFunction = (node: Node): Node | null => {\n let current = node.parent;\n while (isNode(current)) {\n if (functionTypes.has(current.type)) return current;\n current = current.parent;\n }\n return null;\n};\n\nconst plugin: Plugin = testOnlyPlugin(\n \"no-wall-clock-bound\",\n \"noWallClockBound\",\n \"A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n\n const isGlobalMember = (\n node: Node,\n objectName: string,\n member: string,\n ): boolean => {\n if (node.type !== \"MemberExpression\") return false;\n if (propertyName(node.property) !== member || !isNode(node.object))\n return false;\n const binding = resolveBinding(node.object);\n return binding.type === \"global\" && binding.name === objectName;\n };\n\n const isClockRead = (value: unknown): boolean => {\n if (!isNode(value) || value.type !== \"CallExpression\") return false;\n if (!isNode(value.callee)) return false;\n if (\n isGlobalMember(value.callee, \"performance\", \"now\") ||\n isGlobalMember(value.callee, \"Date\", \"now\") ||\n isGlobalMember(value.callee, \"Bun\", \"nanoseconds\")\n )\n return true;\n const callee = value.callee;\n return (\n callee.type === \"MemberExpression\" &&\n propertyName(callee.property) === \"bigint\" &&\n isNode(callee.object) &&\n isGlobalMember(callee.object, \"process\", \"hrtime\")\n );\n };\n\n const constInitializerInSameFunction = (\n identifier: Node,\n use: Node,\n ): Node | null => {\n const name = identifierName(identifier);\n if (name === null) return null;\n let scope: Scope | null = getScope(identifier);\n while (scope !== null) {\n const variable = scope.set.get(name);\n if (variable === undefined) {\n scope = scope.upper;\n continue;\n }\n const definition = variable.defs.at(0);\n if (definition?.type !== \"Variable\") return null;\n const declarator = definition.node as unknown;\n if (\n !isNode(declarator) ||\n !isNode(declarator.parent) ||\n declarator.parent.type !== \"VariableDeclaration\" ||\n declarator.parent.kind !== \"const\" ||\n !isNode(declarator.init) ||\n enclosingFunction(declarator) !== enclosingFunction(use)\n )\n return null;\n return declarator.init;\n }\n return null;\n };\n\n const containsClockRead = (\n value: unknown,\n use: Node,\n followIdentifier: boolean,\n visitedIdentifiers = new Set<Node>(),\n ): boolean => {\n if (Array.isArray(value))\n return value.some((child) =>\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n if (!isNode(value)) return false;\n if (isClockRead(value)) return true;\n if (\n followIdentifier &&\n value.type === \"Identifier\" &&\n isVariableReference(value)\n ) {\n if (visitedIdentifiers.has(value)) return false;\n visitedIdentifiers.add(value);\n const initializer = constInitializerInSameFunction(value, use);\n if (\n initializer !== null &&\n containsClockRead(initializer, use, true, visitedIdentifiers)\n )\n return true;\n }\n return Object.values(value).some(\n (child) =>\n child !== value.parent &&\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n };\n\n const matcherExpectCall = (value: unknown): Node | null => {\n let current = value;\n while (\n isNode(current) &&\n current.type === \"MemberExpression\" &&\n matcherModifiers.has(propertyName(current.property) ?? \"\")\n )\n current = current.object;\n return isNode(current) && current.type === \"CallExpression\"\n ? current\n : null;\n };\n\n const containsSetTimeout = (value: unknown): boolean => {\n if (Array.isArray(value)) return value.some(containsSetTimeout);\n if (!isNode(value)) return false;\n if (value.type === \"CallExpression\" && isNode(value.callee)) {\n const binding = resolveBinding(value.callee);\n if (binding.type === \"global\" && binding.name === \"setTimeout\")\n return true;\n }\n for (const child of Object.values(value)) {\n if (child === value.parent) continue;\n if (Array.isArray(child)) {\n if (child.some(containsSetTimeout)) return true;\n } else if (containsSetTimeout(child)) return true;\n }\n return false;\n };\n\n const isTimer = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"NewExpression\") {\n if (!isNode(value.callee)) return false;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"global\" &&\n binding.name === \"Promise\" &&\n containsSetTimeout(value.arguments)\n );\n }\n if (value.type !== \"CallExpression\" || !isNode(value.callee))\n return false;\n if (isGlobalMember(value.callee, \"Bun\", \"sleep\")) return true;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"import\" &&\n timerModules.has(binding.module) &&\n timerHelpers.has(binding.imported)\n );\n };\n\n const isTimerOrBoundTimer = (value: unknown, use: Node): boolean => {\n if (isTimer(value)) return true;\n if (!isNode(value) || value.type !== \"Identifier\") return false;\n const initializer = constInitializerInSameFunction(value, use);\n return initializer !== null && isTimer(initializer);\n };\n\n return {\n CallExpression(node) {\n if (!isNode(node.callee) || node.callee.type !== \"MemberExpression\")\n return;\n const member = propertyName(node.callee.property);\n if (member === \"race\" && isNode(node.callee.object)) {\n const binding = resolveBinding(node.callee.object);\n if (binding.type === \"global\" && binding.name === \"Promise\") {\n const firstArgument = Array.isArray(node.arguments)\n ? node.arguments.at(0)\n : null;\n if (\n isNode(firstArgument) &&\n firstArgument.type === \"ArrayExpression\" &&\n Array.isArray(firstArgument.elements) &&\n firstArgument.elements.some((element) =>\n isTimerOrBoundTimer(element, node),\n )\n )\n report(node);\n return;\n }\n }\n const expectCall = matcherExpectCall(node.callee.object);\n if (expectCall === null || !isNode(expectCall.callee)) return;\n const calleeBinding = resolveBinding(expectCall.callee);\n const isExpect =\n (calleeBinding.type === \"global\" &&\n calleeBinding.name === \"expect\") ||\n (calleeBinding.type === \"import\" &&\n calleeBinding.imported === \"expect\" &&\n testModules.has(calleeBinding.module));\n if (!isExpect) return;\n const assertionValues = [expectCall.arguments, node.arguments];\n if (containsClockRead(assertionValues, node, true)) report(node);\n },\n };\n },\n);\n\nexport default plugin;\n"],"mappings":";;;;;;AAWA,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAS;CAAc;AAAO,CAAC;AAC7D,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAiB;CAAY;AAAQ,CAAC;AACnE,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;AACF,CAAC;AACD,MAAM,mCAAmB,IAAI,IAAI;CAAC;CAAO;CAAW;AAAU,CAAC;AAE/D,MAAM,uBAAuB,eAA8B;CACzD,MAAM,SAAS,WAAW;CAC1B,IAAI,CAACA,wBAAAA,OAAO,MAAM,GAAG,OAAO;CAC5B,IACE,OAAO,SAAS,sBAChB,OAAO,aAAa,cACpB,OAAO,aAAa,MAEpB,OAAO;CACT,KACG,OAAO,SAAS,cACf,OAAO,SAAS,sBAChB,OAAO,SAAS,yBAClB,OAAO,QAAQ,cACf,OAAO,aAAa,QACpB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,sBACf,OAAO,SAAS,oBAChB,OAAO,SAAS,wBAClB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,wBACf,OAAO,SAAS,yBAChB,OAAO,SA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-wall-clock-bound.d.ts
|
|
2
|
-
declare const
|
|
3
|
+
declare const plugin: Plugin;
|
|
3
4
|
//#endregion
|
|
4
|
-
export {
|
|
5
|
+
export { plugin as default };
|
|
5
6
|
//# sourceMappingURL=no-wall-clock-bound.d.mts.map
|
|
@@ -42,7 +42,7 @@ const enclosingFunction = (node) => {
|
|
|
42
42
|
}
|
|
43
43
|
return null;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
const plugin = testOnlyPlugin("no-wall-clock-bound", "noWallClockBound", "A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.", (report, getScope) => {
|
|
46
46
|
const resolveBinding = createBindingResolver(getScope);
|
|
47
47
|
const isGlobalMember = (node, objectName, member) => {
|
|
48
48
|
if (node.type !== "MemberExpression") return false;
|
|
@@ -144,6 +144,6 @@ var no_wall_clock_bound_default = testOnlyPlugin("no-wall-clock-bound", "noWallC
|
|
|
144
144
|
} };
|
|
145
145
|
});
|
|
146
146
|
//#endregion
|
|
147
|
-
export {
|
|
147
|
+
export { plugin as default };
|
|
148
148
|
|
|
149
149
|
//# sourceMappingURL=no-wall-clock-bound.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-wall-clock-bound.mjs","names":[],"sources":["../src/no-wall-clock-bound.ts"],"sourcesContent":["import type { Scope } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n type Node,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst timerModules = new Set([\n \"node:timers/promises\",\n \"timers/promises\",\n \"@stll/test-kit\",\n]);\nconst timerHelpers = new Set([\"delay\", \"setTimeout\", \"sleep\"]);\nconst testModules = new Set([\"@jest/globals\", \"bun:test\", \"vitest\"]);\nconst functionTypes = new Set([\n \"ArrowFunctionExpression\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n]);\nconst matcherModifiers = new Set([\"not\", \"rejects\", \"resolves\"]);\n\nconst isVariableReference = (identifier: Node): boolean => {\n const parent = identifier.parent;\n if (!isNode(parent)) return true;\n if (\n parent.type === \"MemberExpression\" &&\n parent.property === identifier &&\n parent.computed !== true\n )\n return false;\n if (\n (parent.type === \"Property\" ||\n parent.type === \"MethodDefinition\" ||\n parent.type === \"PropertyDefinition\") &&\n parent.key === identifier &&\n parent.computed !== true &&\n parent.value !== identifier\n )\n return false;\n if (\n (parent.type === \"LabeledStatement\" ||\n parent.type === \"BreakStatement\" ||\n parent.type === \"ContinueStatement\") &&\n parent.label === identifier\n )\n return false;\n if (\n (parent.type === \"VariableDeclarator\" ||\n parent.type === \"FunctionDeclaration\" ||\n parent.type === \"FunctionExpression\" ||\n parent.type === \"ClassDeclaration\" ||\n parent.type === \"ClassExpression\") &&\n parent.id === identifier\n )\n return false;\n return true;\n};\n\nconst enclosingFunction = (node: Node): Node | null => {\n let current = node.parent;\n while (isNode(current)) {\n if (functionTypes.has(current.type)) return current;\n current = current.parent;\n }\n return null;\n};\n\nexport default testOnlyPlugin(\n \"no-wall-clock-bound\",\n \"noWallClockBound\",\n \"A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n\n const isGlobalMember = (\n node: Node,\n objectName: string,\n member: string,\n ): boolean => {\n if (node.type !== \"MemberExpression\") return false;\n if (propertyName(node.property) !== member || !isNode(node.object))\n return false;\n const binding = resolveBinding(node.object);\n return binding.type === \"global\" && binding.name === objectName;\n };\n\n const isClockRead = (value: unknown): boolean => {\n if (!isNode(value) || value.type !== \"CallExpression\") return false;\n if (!isNode(value.callee)) return false;\n if (\n isGlobalMember(value.callee, \"performance\", \"now\") ||\n isGlobalMember(value.callee, \"Date\", \"now\") ||\n isGlobalMember(value.callee, \"Bun\", \"nanoseconds\")\n )\n return true;\n const callee = value.callee;\n return (\n callee.type === \"MemberExpression\" &&\n propertyName(callee.property) === \"bigint\" &&\n isNode(callee.object) &&\n isGlobalMember(callee.object, \"process\", \"hrtime\")\n );\n };\n\n const constInitializerInSameFunction = (\n identifier: Node,\n use: Node,\n ): Node | null => {\n const name = identifierName(identifier);\n if (name === null) return null;\n let scope: Scope | null = getScope(identifier);\n while (scope !== null) {\n const variable = scope.set.get(name);\n if (variable === undefined) {\n scope = scope.upper;\n continue;\n }\n const definition = variable.defs.at(0);\n if (definition?.type !== \"Variable\") return null;\n const declarator = definition.node as unknown;\n if (\n !isNode(declarator) ||\n !isNode(declarator.parent) ||\n declarator.parent.type !== \"VariableDeclaration\" ||\n declarator.parent.kind !== \"const\" ||\n !isNode(declarator.init) ||\n enclosingFunction(declarator) !== enclosingFunction(use)\n )\n return null;\n return declarator.init;\n }\n return null;\n };\n\n const containsClockRead = (\n value: unknown,\n use: Node,\n followIdentifier: boolean,\n visitedIdentifiers = new Set<Node>(),\n ): boolean => {\n if (Array.isArray(value))\n return value.some((child) =>\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n if (!isNode(value)) return false;\n if (isClockRead(value)) return true;\n if (\n followIdentifier &&\n value.type === \"Identifier\" &&\n isVariableReference(value)\n ) {\n if (visitedIdentifiers.has(value)) return false;\n visitedIdentifiers.add(value);\n const initializer = constInitializerInSameFunction(value, use);\n if (\n initializer !== null &&\n containsClockRead(initializer, use, true, visitedIdentifiers)\n )\n return true;\n }\n return Object.values(value).some(\n (child) =>\n child !== value.parent &&\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n };\n\n const matcherExpectCall = (value: unknown): Node | null => {\n let current = value;\n while (\n isNode(current) &&\n current.type === \"MemberExpression\" &&\n matcherModifiers.has(propertyName(current.property) ?? \"\")\n )\n current = current.object;\n return isNode(current) && current.type === \"CallExpression\"\n ? current\n : null;\n };\n\n const containsSetTimeout = (value: unknown): boolean => {\n if (Array.isArray(value)) return value.some(containsSetTimeout);\n if (!isNode(value)) return false;\n if (value.type === \"CallExpression\" && isNode(value.callee)) {\n const binding = resolveBinding(value.callee);\n if (binding.type === \"global\" && binding.name === \"setTimeout\")\n return true;\n }\n for (const child of Object.values(value)) {\n if (child === value.parent) continue;\n if (Array.isArray(child)) {\n if (child.some(containsSetTimeout)) return true;\n } else if (containsSetTimeout(child)) return true;\n }\n return false;\n };\n\n const isTimer = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"NewExpression\") {\n if (!isNode(value.callee)) return false;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"global\" &&\n binding.name === \"Promise\" &&\n containsSetTimeout(value.arguments)\n );\n }\n if (value.type !== \"CallExpression\" || !isNode(value.callee))\n return false;\n if (isGlobalMember(value.callee, \"Bun\", \"sleep\")) return true;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"import\" &&\n timerModules.has(binding.module) &&\n timerHelpers.has(binding.imported)\n );\n };\n\n const isTimerOrBoundTimer = (value: unknown, use: Node): boolean => {\n if (isTimer(value)) return true;\n if (!isNode(value) || value.type !== \"Identifier\") return false;\n const initializer = constInitializerInSameFunction(value, use);\n return initializer !== null && isTimer(initializer);\n };\n\n return {\n CallExpression(node) {\n if (!isNode(node.callee) || node.callee.type !== \"MemberExpression\")\n return;\n const member = propertyName(node.callee.property);\n if (member === \"race\" && isNode(node.callee.object)) {\n const binding = resolveBinding(node.callee.object);\n if (binding.type === \"global\" && binding.name === \"Promise\") {\n const firstArgument = Array.isArray(node.arguments)\n ? node.arguments.at(0)\n : null;\n if (\n isNode(firstArgument) &&\n firstArgument.type === \"ArrayExpression\" &&\n Array.isArray(firstArgument.elements) &&\n firstArgument.elements.some((element) =>\n isTimerOrBoundTimer(element, node),\n )\n )\n report(node);\n return;\n }\n }\n const expectCall = matcherExpectCall(node.callee.object);\n if (expectCall === null || !isNode(expectCall.callee)) return;\n const calleeBinding = resolveBinding(expectCall.callee);\n const isExpect =\n (calleeBinding.type === \"global\" &&\n calleeBinding.name === \"expect\") ||\n (calleeBinding.type === \"import\" &&\n calleeBinding.imported === \"expect\" &&\n testModules.has(calleeBinding.module));\n if (!isExpect) return;\n const assertionValues = [expectCall.arguments, node.arguments];\n if (containsClockRead(assertionValues, node, true)) report(node);\n },\n };\n },\n);\n"],"mappings":";;AAWA,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAS;CAAc;AAAO,CAAC;AAC7D,MAAM,8BAAc,IAAI,IAAI;CAAC;CAAiB;CAAY;AAAQ,CAAC;AACnE,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;AACF,CAAC;AACD,MAAM,mCAAmB,IAAI,IAAI;CAAC;CAAO;CAAW;AAAU,CAAC;AAE/D,MAAM,uBAAuB,eAA8B;CACzD,MAAM,SAAS,WAAW;CAC1B,IAAI,CAAC,OAAO,MAAM,GAAG,OAAO;CAC5B,IACE,OAAO,SAAS,sBAChB,OAAO,aAAa,cACpB,OAAO,aAAa,MAEpB,OAAO;CACT,KACG,OAAO,SAAS,cACf,OAAO,SAAS,sBAChB,OAAO,SAAS,yBAClB,OAAO,QAAQ,cACf,OAAO,aAAa,QACpB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,sBACf,OAAO,SAAS,oBAChB,OAAO,SAAS,wBAClB,OAAO,UAAU,YAEjB,OAAO;CACT,KACG,OAAO,SAAS,wBACf,OAAO,SAAS,yBAChB,OAAO,SAAS,wBAChB,OAAO,SAAS,sBAChB,OAAO,SAAS,sBAClB,OAAO,OAAO,YAEd,OAAO;CACT,OAAO;AACT;AAEA,MAAM,qBAAqB,SAA4B;CACrD,IAAI,UAAU,KAAK;CACnB,OAAO,OAAO,OAAO,GAAG;EACtB,IAAI,cAAc,IAAI,QAAQ,IAAI,GAAG,OAAO;EAC5C,UAAU,QAAQ;CACpB;CACA,OAAO;AACT;AAEA,IAAA,8BAAe,eACb,uBACA,oBACA,yKACC,QAAQ,aAAa;CACpB,MAAM,iBAAiB,sBAAsB,QAAQ;CAErD,MAAM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pB,cAAc,SAAS,qBACvB,MAAM,QAAQ,cAAc,QAAQ,KACpC,cAAc,SAAS,MAAM,YAC3B,oBAAoB,SAAS,IAAI,CACnC,GAEA,OAAO,IAAI;IACb;GACF;EACF;EACA,MAAM,aAAa,kBAAkB,KAAK,OAAO,MAAM;EACvD,IAAI,eAAe,QAAQ,CAAC,OAAO,WAAW,MAAM,GAAG;EACvD,MAAM,gBAAgB,eAAe,WAAW,MAAM;EAOtD,IAAI,EALD,cAAc,SAAS,YACtB,cAAc,SAAS,YACxB,cAAc,SAAS,YACtB,cAAc,aAAa,YAC3B,YAAY,IAAI,cAAc,MAAM,IACzB;EACf,MAAM,kBAAkB,CAAC,WAAW,WAAW,KAAK,SAAS;EAC7D,IAAI,kBAAkB,iBAAiB,MAAM,IAAI,GAAG,OAAO,IAAI;CACjE,EACF;AACF,CACF"}
|
|
1
|
+
{"version":3,"file":"no-wall-clock-bound.mjs","names":[],"sources":["../src/no-wall-clock-bound.ts"],"sourcesContent":["import type { Plugin, Scope } from \"@oxlint/plugins\";\n\nimport {\n createBindingResolver,\n identifierName,\n isNode,\n type Node,\n propertyName,\n testOnlyPlugin,\n} from \"./test-rule-utils\";\n\nconst timerModules = new Set([\n \"node:timers/promises\",\n \"timers/promises\",\n \"@stll/test-kit\",\n]);\nconst timerHelpers = new Set([\"delay\", \"setTimeout\", \"sleep\"]);\nconst testModules = new Set([\"@jest/globals\", \"bun:test\", \"vitest\"]);\nconst functionTypes = new Set([\n \"ArrowFunctionExpression\",\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n]);\nconst matcherModifiers = new Set([\"not\", \"rejects\", \"resolves\"]);\n\nconst isVariableReference = (identifier: Node): boolean => {\n const parent = identifier.parent;\n if (!isNode(parent)) return true;\n if (\n parent.type === \"MemberExpression\" &&\n parent.property === identifier &&\n parent.computed !== true\n )\n return false;\n if (\n (parent.type === \"Property\" ||\n parent.type === \"MethodDefinition\" ||\n parent.type === \"PropertyDefinition\") &&\n parent.key === identifier &&\n parent.computed !== true &&\n parent.value !== identifier\n )\n return false;\n if (\n (parent.type === \"LabeledStatement\" ||\n parent.type === \"BreakStatement\" ||\n parent.type === \"ContinueStatement\") &&\n parent.label === identifier\n )\n return false;\n if (\n (parent.type === \"VariableDeclarator\" ||\n parent.type === \"FunctionDeclaration\" ||\n parent.type === \"FunctionExpression\" ||\n parent.type === \"ClassDeclaration\" ||\n parent.type === \"ClassExpression\") &&\n parent.id === identifier\n )\n return false;\n return true;\n};\n\nconst enclosingFunction = (node: Node): Node | null => {\n let current = node.parent;\n while (isNode(current)) {\n if (functionTypes.has(current.type)) return current;\n current = current.parent;\n }\n return null;\n};\n\nconst plugin: Plugin = testOnlyPlugin(\n \"no-wall-clock-bound\",\n \"noWallClockBound\",\n \"A test must not assert on measured wall-clock time or race a timer, because such assertions fail on loaded runners; use a controlled clock or deferred for ordering.\",\n (report, getScope) => {\n const resolveBinding = createBindingResolver(getScope);\n\n const isGlobalMember = (\n node: Node,\n objectName: string,\n member: string,\n ): boolean => {\n if (node.type !== \"MemberExpression\") return false;\n if (propertyName(node.property) !== member || !isNode(node.object))\n return false;\n const binding = resolveBinding(node.object);\n return binding.type === \"global\" && binding.name === objectName;\n };\n\n const isClockRead = (value: unknown): boolean => {\n if (!isNode(value) || value.type !== \"CallExpression\") return false;\n if (!isNode(value.callee)) return false;\n if (\n isGlobalMember(value.callee, \"performance\", \"now\") ||\n isGlobalMember(value.callee, \"Date\", \"now\") ||\n isGlobalMember(value.callee, \"Bun\", \"nanoseconds\")\n )\n return true;\n const callee = value.callee;\n return (\n callee.type === \"MemberExpression\" &&\n propertyName(callee.property) === \"bigint\" &&\n isNode(callee.object) &&\n isGlobalMember(callee.object, \"process\", \"hrtime\")\n );\n };\n\n const constInitializerInSameFunction = (\n identifier: Node,\n use: Node,\n ): Node | null => {\n const name = identifierName(identifier);\n if (name === null) return null;\n let scope: Scope | null = getScope(identifier);\n while (scope !== null) {\n const variable = scope.set.get(name);\n if (variable === undefined) {\n scope = scope.upper;\n continue;\n }\n const definition = variable.defs.at(0);\n if (definition?.type !== \"Variable\") return null;\n const declarator = definition.node as unknown;\n if (\n !isNode(declarator) ||\n !isNode(declarator.parent) ||\n declarator.parent.type !== \"VariableDeclaration\" ||\n declarator.parent.kind !== \"const\" ||\n !isNode(declarator.init) ||\n enclosingFunction(declarator) !== enclosingFunction(use)\n )\n return null;\n return declarator.init;\n }\n return null;\n };\n\n const containsClockRead = (\n value: unknown,\n use: Node,\n followIdentifier: boolean,\n visitedIdentifiers = new Set<Node>(),\n ): boolean => {\n if (Array.isArray(value))\n return value.some((child) =>\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n if (!isNode(value)) return false;\n if (isClockRead(value)) return true;\n if (\n followIdentifier &&\n value.type === \"Identifier\" &&\n isVariableReference(value)\n ) {\n if (visitedIdentifiers.has(value)) return false;\n visitedIdentifiers.add(value);\n const initializer = constInitializerInSameFunction(value, use);\n if (\n initializer !== null &&\n containsClockRead(initializer, use, true, visitedIdentifiers)\n )\n return true;\n }\n return Object.values(value).some(\n (child) =>\n child !== value.parent &&\n containsClockRead(child, use, followIdentifier, visitedIdentifiers),\n );\n };\n\n const matcherExpectCall = (value: unknown): Node | null => {\n let current = value;\n while (\n isNode(current) &&\n current.type === \"MemberExpression\" &&\n matcherModifiers.has(propertyName(current.property) ?? \"\")\n )\n current = current.object;\n return isNode(current) && current.type === \"CallExpression\"\n ? current\n : null;\n };\n\n const containsSetTimeout = (value: unknown): boolean => {\n if (Array.isArray(value)) return value.some(containsSetTimeout);\n if (!isNode(value)) return false;\n if (value.type === \"CallExpression\" && isNode(value.callee)) {\n const binding = resolveBinding(value.callee);\n if (binding.type === \"global\" && binding.name === \"setTimeout\")\n return true;\n }\n for (const child of Object.values(value)) {\n if (child === value.parent) continue;\n if (Array.isArray(child)) {\n if (child.some(containsSetTimeout)) return true;\n } else if (containsSetTimeout(child)) return true;\n }\n return false;\n };\n\n const isTimer = (value: unknown): boolean => {\n if (!isNode(value)) return false;\n if (value.type === \"NewExpression\") {\n if (!isNode(value.callee)) return false;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"global\" &&\n binding.name === \"Promise\" &&\n containsSetTimeout(value.arguments)\n );\n }\n if (value.type !== \"CallExpression\" || !isNode(value.callee))\n return false;\n if (isGlobalMember(value.callee, \"Bun\", \"sleep\")) return true;\n const binding = resolveBinding(value.callee);\n return (\n binding.type === \"import\" &&\n timerModules.has(binding.module) &&\n timerHelpers.has(binding.imported)\n );\n };\n\n const isTimerOrBoundTimer = (value: unknown, use: Node): boolean => {\n if (isTimer(value)) return true;\n if (!isNode(value) || value.type !== \"Identifier\") return false;\n const initializer = constInitializerInSameFunction(value, use);\n return initializer !== null && isTimer(initializer);\n };\n\n return {\n CallExpression(node) {\n if (!isNode(node.callee) || node.callee.type !== \"MemberExpression\")\n return;\n const member = propertyName(node.callee.property);\n if (member === \"race\" && isNode(node.callee.object)) {\n const binding = resolveBinding(node.callee.object);\n if (binding.type === \"global\" && binding.name === \"Promise\") {\n const firstArgument = Array.isArray(node.arguments)\n ? node.arguments.at(0)\n : null;\n if (\n isNode(firstArgument) &&\n firstArgument.type === \"ArrayExpression\" &&\n Array.isArray(firstArgument.elements) &&\n firstArgument.elements.some((element) =>\n isTimerOrBoundTimer(element, node),\n )\n )\n report(node);\n return;\n }\n }\n const expectCall = matcherExpectCall(node.callee.object);\n if (expectCall === null || !isNode(expectCall.callee)) return;\n const calleeBinding = resolveBinding(expectCall.callee);\n const isExpect =\n (calleeBinding.type === \"global\" &&\n calleeBinding.name === \"expect\") ||\n (calleeBinding.type === \"import\" &&\n calleeBinding.imported === \"expect\" &&\n testModules.has(calleeBinding.module));\n if (!isExpect) return;\n const assertionValues = [expectCall.arguments, node.arguments];\n if (containsClockRead(assertionValues, node, true)) report(node);\n },\n };\n },\n);\n\nexport default plugin;\n"],"mappings":";;AAWA,MAAM,+BAAe,IAAI,IAAI;CAC3B;CACA;CACA;AACF,CAAC;AACD,MAAM,+BAA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AI,eAAe,QAAQ,CAAC,OAAO,WAAW,MAAM,GAAG;EACvD,MAAM,gBAAgB,eAAe,WAAW,MAAM;EAOtD,IAAI,EALD,cAAc,SAAS,YACtB,cAAc,SAAS,YACxB,cAAc,SAAS,YACtB,cAAc,aAAa,YAC3B,YAAY,IAAI,cAAc,MAAM,IACzB;EACf,MAAM,kBAAkB,CAAC,WAAW,WAAW,KAAK,SAAS;EAC7D,IAAI,kBAAkB,iBAAiB,MAAM,IAAI,GAAG,OAAO,IAAI;CACjE,EACF;AACF,CACF"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
const require_test_rule_utils = require("./test-rule-utils.cjs");
|
|
6
6
|
//#region src/no-wall-clock-in-tests.ts
|
|
7
|
-
|
|
7
|
+
const plugin = require_test_rule_utils.testOnlyPlugin("no-wall-clock-in-tests", "noWallClock", "Use the @stll/test-kit clock instead of reading the wall clock in tests.", (report, getScope) => {
|
|
8
8
|
const resolveBinding = require_test_rule_utils.createBindingResolver(getScope);
|
|
9
9
|
const isGlobal = (value, name) => {
|
|
10
10
|
if (!require_test_rule_utils.isNode(value)) return false;
|
|
@@ -30,6 +30,6 @@ var no_wall_clock_in_tests_default = require_test_rule_utils.testOnlyPlugin("no-
|
|
|
30
30
|
};
|
|
31
31
|
});
|
|
32
32
|
//#endregion
|
|
33
|
-
exports.default =
|
|
33
|
+
exports.default = plugin;
|
|
34
34
|
|
|
35
35
|
//# sourceMappingURL=no-wall-clock-in-tests.cjs.map
|