π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Enforce generated WASM API naming
Manav Rathi32a37a09359d
diff --git a/web/checks/wasm-names/eslint.config.mjs b/web/checks/wasm-names/eslint.config.mjsnew file mode 100644index 0000000000..8eba84fc69--- /dev/null+++ b/web/checks/wasm-names/eslint.config.mjs@@ -0,0 +1,20 @@+import tseslint from "typescript-eslint";++export default [+ { ignores: ["**/*.wasm.d.ts"] },+ {+ files: ["packages/wasm/*/pkg/*.d.ts"],+ languageOptions: { parser: tseslint.parser },+ plugins: { "@typescript-eslint": tseslint.plugin },+ rules: {+ "@typescript-eslint/naming-convention": [+ "error",+ {+ selector: ["function", "method", "property", "accessor"],+ format: ["camelCase"],+ },+ { selector: "typeLike", format: ["PascalCase"] },+ ],+ },+ },+];diff --git a/web/checks/wasm-names/test.mjs b/web/checks/wasm-names/test.mjsnew file mode 100644index 0000000000..a9bd4cd256--- /dev/null+++ b/web/checks/wasm-names/test.mjs@@ -0,0 +1,60 @@+import { ESLint } from "eslint";+import assert from "node:assert/strict";+import { resolve } from "node:path";+import test from "node:test";++const eslint = new ESLint({+ cwd: resolve(import.meta.dirname, "../.."),+ overrideConfigFile: resolve(import.meta.dirname, "eslint.config.mjs"),+ allowInlineConfig: false,+});+const filePath = "packages/wasm/example/pkg/ente_example_wasm.d.ts";++test("generated APIs allow Rust parameters and disposal hooks", async () => {+ const [result] = await eslint.lintText(+ `/* eslint-disable */+ export interface ResultData { publicKey: string; }+ export class CryptoKey {+ private constructor();+ free(): void;+ [Symbol.dispose](): void;+ computeValue(rust_parameter: string): ResultData;+ readonly publicKey: string;+ get currentValue(): number;+ }+ export function deriveKey(key_bytes: Uint8Array): CryptoKey;`,+ { filePath },+ );+ assert.deepEqual(result.messages, []);+});++test("generated API naming cannot be suppressed inline", async () => {+ const [result] = await eslint.lintText(+ `/* eslint-disable */+ export interface result_data { public_key: string; }+ export class crypto_key {+ compute_value(): void;+ readonly secret_key: string;+ get current_value(): number;+ }+ // eslint-disable-next-line @typescript-eslint/naming-convention+ export function derive_key(): void;`,+ { filePath },+ );+ assert.equal(result.messages.length, 7);+ assert.ok(+ result.messages.every(+ ({ ruleId, severity }) =>+ ruleId === "@typescript-eslint/naming-convention" &&+ severity === 2,+ ),+ );+});++test("low-level WASM declarations are excluded", async () => {+ assert.ok(+ await eslint.isPathIgnored(+ "packages/wasm/example/pkg/ente_example_wasm_bg.wasm.d.ts",+ ),+ );+});diff --git a/web/package.json b/web/package.jsonindex 1294fe0a96..6ea61bbcde 100644--- a/web/package.json+++ b/web/package.json@@ -34,6 +34,7 @@"build:twoof3": "npm exec --workspace twoof3 -- next build --webpack","build:wasm": "npm run build:prelogin-wasm && npm run build:cast-wasm && npm run build:ensu-wasm && npm run build:legacy-wasm && npm run build:locker-wasm && npm run build:paste-wasm && npm run build:photos-wasm && npm run build:space-wasm","check:wasm-imports": "eslint --config checks/wasm-imports/eslint.config.mjs --parser @typescript-eslint/parser --no-inline-config --max-warnings 0 apps packages && node checks/wasm-imports/entrypoints.mjs && node --test checks/wasm-imports/test.mjs",+ "check:wasm-names": "eslint --config checks/wasm-names/eslint.config.mjs --no-inline-config --max-warnings 0 'packages/wasm/*/pkg/*.d.ts' && node --test checks/wasm-names/test.mjs","dev": "npm run dev:photos","dev:accounts": "npm run build:prelogin-wasm && npm exec --workspace accounts -- next dev --webpack -p 3001","dev:albums": "npm run build:prelogin-wasm && npm exec --workspace albums -- next dev --webpack -p 3002",@@ -50,7 +51,7 @@"dev:share": "npm run build:prelogin-wasm && npm exec --workspace share -- next dev --webpack -p 3005","dev:space": "npm run build:prelogin-wasm && npm run build:space-wasm && npm exec --workspace space -- next dev --webpack -p 3013","dev:twoof3": "npm exec --workspace twoof3 -- next dev --webpack -p 3012",- "lint": "concurrently --names 'prettier,eslint,tsc,wasm-imports' \"prettier --check --log-level warn .\" \"npm exec --workspaces -- eslint --max-warnings 0\" \"npm exec --workspaces -- tsc\" \"npm run check:wasm-imports\"",+ "lint": "concurrently --names 'prettier,eslint,tsc,wasm-imports,wasm-names' \"prettier --check --log-level warn .\" \"npm exec --workspaces -- eslint --max-warnings 0\" \"npm exec --workspaces -- tsc\" \"npm run check:wasm-imports\" \"npm run check:wasm-names\"","lint:fix": "concurrently --names 'prettier,eslint,tsc' \"prettier --write --log-level warn .\" \"npm exec --workspaces -- eslint --fix --max-warnings 0\" \"npm exec --workspaces -- tsc\"","test": "npm run test --workspace ente-prelogin-wasm && npm run test --workspace ente-locker-wasm && npm run test --workspace ente-paste-wasm && npm run test --workspace ente-contacts && npm run test --workspace locker && npm run test --workspace paste && npm run test --workspace photos && npm run test --workspace space"},