From 1ee5ffbbe8a64da5a83da889dd16d41c3463c332 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Tue, 24 Sep 2024 01:15:14 -0700 Subject: [PATCH] Clean up web code errors and make CI enforce them --- frontend/.eslintrc.cjs | 2 +- frontend/package-installer.js | 2 +- frontend/package.json | 5 +- .../floating-menus/ColorPicker.svelte | 4 +- .../components/floating-menus/MenuList.svelte | 6 +- frontend/src/components/views/Graph.svelte | 4 +- .../widgets/buttons/TextButton.svelte | 7 +-- .../widgets/inputs/DropdownInput.svelte | 4 +- .../widgets/inputs/ScrollbarInput.svelte | 2 +- .../window/title-bar/TitleBar.svelte | 3 +- .../computational-geometry.ts | 26 --------- frontend/src/wasm-communication/messages.ts | 56 +++++-------------- frontend/wasm/tests/web.rs | 10 ---- website/other/bezier-rs-demos/.eslintrc.cjs | 12 ++-- .../bezier-rs-demos/package-installer.js | 2 +- website/other/bezier-rs-demos/package.json | 4 +- website/other/bezier-rs-demos/tsconfig.json | 23 ++------ website/templates/base.html | 1 + 18 files changed, 44 insertions(+), 129 deletions(-) delete mode 100644 frontend/src/utility-functions/computational-geometry.ts delete mode 100644 frontend/wasm/tests/web.rs diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs index 32485f10bf..8eb7f7bc8e 100644 --- a/frontend/.eslintrc.cjs +++ b/frontend/.eslintrc.cjs @@ -40,7 +40,7 @@ module.exports = { }, { extends: ["plugin:@typescript-eslint/disable-type-checked"], - files: [".eslintrc.cjs"], + files: ["./*.js", "./*.cjs"], }, ], rules: { diff --git a/frontend/package-installer.js b/frontend/package-installer.js index 6af29e88c4..64970e38a6 100644 --- a/frontend/package-installer.js +++ b/frontend/package-installer.js @@ -30,7 +30,7 @@ if (isInstallNeeded()) { // eslint-disable-next-line no-console console.log("Finished installing npm packages."); - } catch (error) { + } catch (_) { // eslint-disable-next-line no-console console.error("Failed to install npm packages. Please run `npm install` from the `/frontend` directory."); process.exit(1); diff --git a/frontend/package.json b/frontend/package.json index d0e25144ce..0280399fd3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,8 +15,8 @@ "build-profiling": "npm run wasm:build-profiling && vite build", "build": "npm run wasm:build-production && vite build", "---------- UTILITIES ----------": "", - "lint": "eslint .", - "lint-fix": "eslint . --fix", + "lint": "eslint . && tsc --noEmit", + "lint-fix": "eslint . --fix && tsc --noEmit", "---------- INTERNAL ----------": "", "setup": "node package-installer.js", "wasm:build-dev": "wasm-pack build ./wasm --dev --target=web", @@ -30,7 +30,6 @@ "@tauri-apps/api": "^1.6.0", "class-transformer": "^0.5.1", "idb-keyval": "^6.2.1", - "paper": "^0.12.18", "reflect-metadata": "^0.2.2" }, "devDependencies": { diff --git a/frontend/src/components/floating-menus/ColorPicker.svelte b/frontend/src/components/floating-menus/ColorPicker.svelte index c525ec6464..a19a9eab02 100644 --- a/frontend/src/components/floating-menus/ColorPicker.svelte +++ b/frontend/src/components/floating-menus/ColorPicker.svelte @@ -203,7 +203,7 @@ function setColorRGB(channel: keyof RGB, strength: number | undefined) { // Do nothing if the given value is undefined - if (strength === undefined) undefined; + if (strength === undefined) return undefined; // Set the specified channel to the given value else if (channel === "r") setColor(new Color(strength / 255, newColor.green, newColor.blue, newColor.alpha)); else if (channel === "g") setColor(new Color(newColor.red, strength / 255, newColor.blue, newColor.alpha)); @@ -212,7 +212,7 @@ function setColorHSV(channel: keyof HSV, strength: number | undefined) { // Do nothing if the given value is undefined - if (strength === undefined) undefined; + if (strength === undefined) return undefined; // Set the specified channel to the given value else if (channel === "h") hue = strength / 360; else if (channel === "s") saturation = strength / 100; diff --git a/frontend/src/components/floating-menus/MenuList.svelte b/frontend/src/components/floating-menus/MenuList.svelte index b7f494fb1d..e693d460ac 100644 --- a/frontend/src/components/floating-menus/MenuList.svelte +++ b/frontend/src/components/floating-menus/MenuList.svelte @@ -219,7 +219,7 @@ childReference.open = true; // The reason we bother taking `highlightdEntry` as an argument is because, when this function is called, it can ensure `highlightedEntry` is not undefined. - // But here we still have to set `highlighted` to itself so Svelte knows to reactively update it after we set its `.ref.open` property. + // But here we still have to set `highlighted` to itself so Svelte knows to reactively update it after we set its `childReference.open` property. highlighted = highlighted; // Highlight first item @@ -452,11 +452,11 @@ {#if entry.children} { + on:naturalWidth={({ detail }) => { // We do a manual dispatch here instead of just `on:naturalWidth` as a workaround for the diff --git a/frontend/src/components/widgets/inputs/DropdownInput.svelte b/frontend/src/components/widgets/inputs/DropdownInput.svelte index 542b464daa..e8762d21e6 100644 --- a/frontend/src/components/widgets/inputs/DropdownInput.svelte +++ b/frontend/src/components/widgets/inputs/DropdownInput.svelte @@ -48,7 +48,7 @@ activeEntrySkipWatcher = false; } else if (activeEntry !== DASH_ENTRY) { // We need to set to the initial value first to track a right history step, as if we hover in initial selection. - dispatch("hoverInEntry", initialSelectedIndex); + if (initialSelectedIndex !== undefined) dispatch("hoverInEntry", initialSelectedIndex); dispatch("selectedIndex", entries.flat().indexOf(activeEntry)); } } @@ -58,7 +58,7 @@ } function dispatchHoverOutEntry() { - dispatch("hoverOutEntry", initialSelectedIndex); + if (initialSelectedIndex !== undefined) dispatch("hoverOutEntry", initialSelectedIndex); } function makeActiveEntry(): MenuListEntry { diff --git a/frontend/src/components/widgets/inputs/ScrollbarInput.svelte b/frontend/src/components/widgets/inputs/ScrollbarInput.svelte index 3bc7a93ac8..c8497bf8c9 100644 --- a/frontend/src/components/widgets/inputs/ScrollbarInput.svelte +++ b/frontend/src/components/widgets/inputs/ScrollbarInput.svelte @@ -14,7 +14,7 @@ const pointerPosition = (direction: ScrollbarDirection, e: PointerEvent): number => (direction === "Vertical" ? e.clientY : e.clientX); - const dispatch = createEventDispatcher<{ handlePosition: number; pressTrack: number; pointerup }>(); + const dispatch = createEventDispatcher<{ handlePosition: number; pressTrack: number; pointerup: undefined }>(); export let direction: ScrollbarDirection = "Vertical"; export let handlePosition = 0.5; diff --git a/frontend/src/components/window/title-bar/TitleBar.svelte b/frontend/src/components/window/title-bar/TitleBar.svelte index 54fad18f4a..e08bcfc353 100644 --- a/frontend/src/components/window/title-bar/TitleBar.svelte +++ b/frontend/src/components/window/title-bar/TitleBar.svelte @@ -59,10 +59,9 @@ // New fields in `MenuListEntry` shortcutRequiresLock: entry.shortcut ? shortcutRequiresLock(entry.shortcut.keys) : undefined, - value: undefined, + value: "", disabled: entry.disabled ?? undefined, font: undefined, - ref: undefined, }); entries = updateMenuBarLayout.layout.map(menuBarEntryToMenuListEntry); diff --git a/frontend/src/utility-functions/computational-geometry.ts b/frontend/src/utility-functions/computational-geometry.ts deleted file mode 100644 index f0361ba43d..0000000000 --- a/frontend/src/utility-functions/computational-geometry.ts +++ /dev/null @@ -1,26 +0,0 @@ -import paper from "paper/dist/paper-core"; - -// Required setup to be used headlessly -paper.setup(new paper.Size(1, 1)); -paper.view.autoUpdate = false; - -export function booleanUnion(path1: string, path2: string): string { - return booleanOperation(path1, path2, "unite"); -} - -export function booleanSubtract(path1: string, path2: string): string { - return booleanOperation(path1, path2, "subtract"); -} - -export function booleanIntersect(path1: string, path2: string): string { - return booleanOperation(path1, path2, "intersect"); -} - -function booleanOperation(path1: string, path2: string, operation: "unite" | "subtract" | "intersect"): string { - const paperPath1 = new paper.CompoundPath(path1); - const paperPath2 = new paper.CompoundPath(path2); - const result = paperPath1[operation](paperPath2); - paperPath1.remove(); - paperPath2.remove(); - return result.pathData; -} diff --git a/frontend/src/wasm-communication/messages.ts b/frontend/src/wasm-communication/messages.ts index 16f03f1a6e..afe81ac821 100644 --- a/frontend/src/wasm-communication/messages.ts +++ b/frontend/src/wasm-communication/messages.ts @@ -12,31 +12,12 @@ export class JsMessage { } const TupleToVec2 = Transform(({ value }: { value: [number, number] | undefined }) => (value === undefined ? undefined : { x: value[0], y: value[1] })); -const ImportsToVec2Array = Transform(({ obj }) => { - const imports: { outputMetadata: FrontendGraphOutput; position: XY }[] = []; - obj.imports.forEach(([outputMetadata, x, y]: [FrontendGraphOutput, number, number]) => { - outputMetadata.connectedTo = outputMetadata.connectedTo.map((connector: any) => { - if (connector.export !== undefined) return { index: connector.export.index }; - return { nodeId: connector.node.nodeId, index: connector.node.inputIndex }; - }); - imports.push({ outputMetadata, position: { x, y } }); - }); - return imports; -}); -const ExportsToVec2Array = Transform(({ obj }) => { - const exports: { inputMetadata: FrontendGraphInput; position: XY }[] = []; - obj.exports.forEach(([inputMetadata, x, y]: [FrontendGraphInput, number, number]) => { - if (inputMetadata.connectedTo !== undefined) { - if (inputMetadata.connectedTo?.import !== undefined) { - inputMetadata.connectedTo = { index: inputMetadata.connectedTo?.import.index }; - } else { - inputMetadata.connectedTo = { nodeId: inputMetadata.connectedTo?.node.nodeId, index: inputMetadata.connectedTo?.node.outputIndex }; - } - } - exports.push({ inputMetadata, position: { x, y } }); - }); - return exports; -}); +const ImportsToVec2Array = Transform(({ obj: { imports } }: { obj: { imports: [FrontendGraphOutput, number, number][] } }) => + imports.map(([outputMetadata, x, y]) => ({ outputMetadata, position: { x, y } })), +); +const ExportsToVec2Array = Transform(({ obj: { exports } }: { obj: { exports: [FrontendGraphInput, number, number][] } }) => + exports.map(([inputMetadata, x, y]) => ({ inputMetadata, position: { x, y } })), +); // const BigIntTupleToVec2 = Transform(({ value }: { value: [bigint, bigint] | undefined }) => (value === undefined ? undefined : { x: Number(value[0]), y: Number(value[1]) })); @@ -187,22 +168,11 @@ export type ContextMenuInformation = { export type FrontendGraphDataType = "General" | "Raster" | "VectorData" | "Number" | "Graphic" | "Artboard"; export class Node { - readonly nodeId!: bigint; readonly index!: bigint; + // Omitted if this Node is an Import or Export to/from the node network + readonly nodeId?: bigint; } -export class Export { - readonly index!: bigint; -} - -export class Import { - readonly index!: bigint; -} - -export type OutputConnector = Node | Import; - -export type InputConnector = Node | Export; - const CreateOutputConnectorOptional = Transform(({ obj }) => { if (obj.connectedTo == undefined) { return undefined; @@ -228,11 +198,11 @@ export class FrontendGraphInput { readonly resolvedType!: string | undefined; @CreateOutputConnectorOptional - connectedTo!: OutputConnector | undefined; + connectedTo!: Node | undefined; } const CreateInputConnectorArray = Transform(({ obj }) => { - const newInputConnectors: InputConnector[] = []; + const newInputConnectors: Node[] = []; obj.connectedTo.forEach((connector: any) => { if (connector.export !== undefined) { newInputConnectors.push({ index: connector.export }); @@ -257,7 +227,7 @@ export class FrontendGraphOutput { readonly resolvedType!: string | undefined; @CreateInputConnectorArray - readonly connectedTo!: InputConnector[]; + connectedTo!: Node[]; } export class FrontendNode { @@ -329,10 +299,10 @@ const CreateInputConnector = Transform(({ obj }) => { export class FrontendNodeWire { @CreateOutputConnector - readonly wireStart!: OutputConnector; + readonly wireStart!: Node; @CreateInputConnector - readonly wireEnd!: InputConnector; + readonly wireEnd!: Node; readonly dashed!: boolean; } diff --git a/frontend/wasm/tests/web.rs b/frontend/wasm/tests/web.rs deleted file mode 100644 index a8f0d29b6b..0000000000 --- a/frontend/wasm/tests/web.rs +++ /dev/null @@ -1,10 +0,0 @@ -// #![cfg(target_arch = "wasm32")] - -// use wasm_bindgen_test::*; - -// wasm_bindgen_test_configure!(run_in_browser); - -// #[wasm_bindgen_test] -// fn pass() { -// assert_eq!(1 + 1, 2); -// } diff --git a/website/other/bezier-rs-demos/.eslintrc.cjs b/website/other/bezier-rs-demos/.eslintrc.cjs index a079a10499..af338b419e 100644 --- a/website/other/bezier-rs-demos/.eslintrc.cjs +++ b/website/other/bezier-rs-demos/.eslintrc.cjs @@ -12,12 +12,6 @@ module.exports = { ecmaVersion: "latest", project: "./tsconfig.json", }, - overrides: [ - { - extends: ["plugin:@typescript-eslint/disable-type-checked"], - files: [".eslintrc.cjs"], - }, - ], ignorePatterns: [ // Ignore generated directories "node_modules/", @@ -28,6 +22,12 @@ module.exports = { "!.*.js", "!.*.ts", ], + overrides: [ + { + extends: ["plugin:@typescript-eslint/disable-type-checked"], + files: ["./*.js", "./*.cjs"], + }, + ], rules: { // Standard ESLint config (for ordinary JS syntax linting) indent: "off", diff --git a/website/other/bezier-rs-demos/package-installer.js b/website/other/bezier-rs-demos/package-installer.js index 6af29e88c4..64970e38a6 100644 --- a/website/other/bezier-rs-demos/package-installer.js +++ b/website/other/bezier-rs-demos/package-installer.js @@ -30,7 +30,7 @@ if (isInstallNeeded()) { // eslint-disable-next-line no-console console.log("Finished installing npm packages."); - } catch (error) { + } catch (_) { // eslint-disable-next-line no-console console.error("Failed to install npm packages. Please run `npm install` from the `/frontend` directory."); process.exit(1); diff --git a/website/other/bezier-rs-demos/package.json b/website/other/bezier-rs-demos/package.json index b38c360fc3..8e377698e4 100644 --- a/website/other/bezier-rs-demos/package.json +++ b/website/other/bezier-rs-demos/package.json @@ -13,8 +13,8 @@ "build-profiling": "npm run wasm:build-profiling && vite build", "build": "npm run wasm:build-production && vite build", "---------- UTILITIES ----------": "", - "lint": "eslint .", - "lint-fix": "eslint . --fix", + "lint": "eslint . && tsc --noEmit", + "lint-fix": "eslint . --fix && tsc --noEmit", "---------- INTERNAL ----------": "", "setup": "node package-installer.js", "wasm:build-dev": "wasm-pack build ./wasm --dev --target=web", diff --git a/website/other/bezier-rs-demos/tsconfig.json b/website/other/bezier-rs-demos/tsconfig.json index dcc6a68cd7..297b6a7e31 100644 --- a/website/other/bezier-rs-demos/tsconfig.json +++ b/website/other/bezier-rs-demos/tsconfig.json @@ -12,27 +12,12 @@ "sourceMap": true, "baseUrl": ".", "paths": { - "@/*": [ - "src/*" - ] + "@/*": ["src/*"] }, - "lib": [ - "esnext", - "dom", - "dom.iterable", - "scripthost" - ] + "lib": ["esnext", "dom", "dom.iterable", "scripthost"] }, - "include": [ - "src/**/*.ts", - "src/**/*.d.ts", - "*.ts", - "*.js", - "*.cjs" - ], - "exclude": [ - "node_modules" - ], + "include": ["src/**/*.ts", "src/**/*.d.ts", "*.ts", "*.js", "*.cjs"], + "exclude": ["node_modules"], "ts-node": { "compilerOptions": { "module": "commonjs", diff --git a/website/templates/base.html b/website/templates/base.html index 0b94d2b1b2..9a347fa581 100644 --- a/website/templates/base.html +++ b/website/templates/base.html @@ -101,6 +101,7 @@