fix(lint): give randomness guidance for crypto values (#3659)

Builds on #1729 in the extracted lint package.

Co-authored-by: AGRO-CODEX <brstopo@gmail.com>
This commit is contained in:
James Russo
2026-09-04 18:39:51 -04:00
committed by GitHub
co-authored by AGRO-CODEX
parent 29efd5dfa8
commit 0ad9c700ac
2 changed files with 20 additions and 1 deletions
+19
View File
@@ -601,6 +601,25 @@ describe("core rules", () => {
});
describe("non_deterministic_code", () => {
it("gives randomness guidance for crypto and clock guidance for wall time", async () => {
const result = await lintHyperframeHtml(`<html><body>
<div data-composition-id="c1" data-width="1920" data-height="1080"></div>
<script>
crypto.getRandomValues(new Uint32Array(1));
Date.now();
window.__timelines = { c1: gsap.timeline({ paused: true }) };
</script>
</body></html>`);
const crypto = result.findings.find((finding) =>
finding.message.includes("crypto.getRandomValues"),
);
const clock = result.findings.find((finding) => finding.message.includes("Date.now"));
expect(crypto).toMatchObject({ code: "non_deterministic_code", severity: "error" });
expect(crypto?.fixHint).toContain("seeded PRNG");
expect(crypto?.fixHint).not.toContain("time-dependent");
expect(clock?.fixHint).toContain("wall-clock time");
});
it("detects Math.random() in script content", async () => {
const html = `
<html><body>
+1 -1
View File
@@ -478,7 +478,7 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [
{
pattern: /crypto\.getRandomValues\s*\(/,
label: "crypto.getRandomValues()",
hint: "Remove time-dependent code. Use a seeded PRNG for deterministic renders.",
hint: "Use a seeded PRNG (e.g. a simple mulberry32) so renders are deterministic across frames.",
},
{
pattern: /gsap\.utils\.random\s*\(/,