Skip to content

Commit fd0cc79

Browse files
ci(ui): fail the lint on the two secure-context-only web APIs
`crypto.randomUUID` was fixed once in #1868 and came back when the interface was rewritten and the file holding the helper went with it. A note in a file is lost the same way twice, so the rule states it where a rewrite cannot drop it, and names the helper to use instead. `navigator.clipboard` is listed for the same reason: bare, it fails silently rather than loudly. Signed-off-by: Nicholas Bucher <[email protected]>
1 parent 91c0ef9 commit fd0cc79

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎ui/eslint.config.mjs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,36 @@ export default tseslint.config(
3939
},
4040
},
4141

42+
/*
43+
* Two web APIs that only exist in a secure context, and the helpers that stand
44+
* in for them.
45+
*
46+
* Both were called bare once already: `crypto.randomUUID` threw on every page
47+
* that minted an id over plain http, and `navigator.clipboard?.writeText` was a
48+
* silent no-op there. The first was fixed in #1868 and lost again when the
49+
* interface was rewritten, which is the argument for a rule rather than a note:
50+
* the knowledge has to survive the next rewrite of the file that holds it.
51+
*/
52+
{
53+
files: ["src/**/*.{ts,tsx}"],
54+
ignores: ["src/api/randomId.ts", "src/components/common/copyText.ts"],
55+
rules: {
56+
"no-restricted-syntax": [
57+
"error",
58+
{
59+
selector: "MemberExpression[property.name='randomUUID']",
60+
message:
61+
"crypto.randomUUID is undefined outside a secure context — over plain http from anything but localhost it throws. Use randomId() from @/api/randomId.",
62+
},
63+
{
64+
selector: "MemberExpression[property.name='clipboard']",
65+
message:
66+
"navigator.clipboard is undefined outside a secure context, so a copy there does nothing and says nothing. Use copyText() from @/components/common/copyText.",
67+
},
68+
],
69+
},
70+
},
71+
4272
/*
4373
* The browser suite's conventions, enforced rather than only written down.
4474
*

0 commit comments

Comments
 (0)