Skip to content

Commit

Permalink
Clean up web code errors and make CI enforce them
Browse files Browse the repository at this point in the history
  • Loading branch information
Keavon committed Sep 24, 2024
1 parent 14de67c commit 1ee5ffb
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 129 deletions.
2 changes: 1 addition & 1 deletion frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
},
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: [".eslintrc.cjs"],
files: ["./*.js", "./*.cjs"],
},
],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/package-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/floating-menus/ColorPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/floating-menus/MenuList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -452,11 +452,11 @@

{#if entry.children}
<MenuList
on:naturalWidth={() => {
on:naturalWidth={({ detail }) => {
// We do a manual dispatch here instead of just `on:naturalWidth` as a workaround for the <script> tag
// at the top of this file displaying a "'render' implicitly has return type 'any' because..." error.
// See explanation at <https://github.com/sveltejs/language-tools/issues/452#issuecomment-723148184>.
dispatch("naturalWidth");
dispatch("naturalWidth", detail);
}}
open={getChildReference(entry)?.open || false}
direction="TopRight"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/views/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@
const { nodeOutput, nodeInput } = resolveWire(wire);
if (!nodeOutput || !nodeInput) return [];
const wireStartNode = $nodeGraph.nodes.get((wire.wireStart as Node).nodeId);
const wireStartNode = wire.wireStart.nodeId !== undefined ? $nodeGraph.nodes.get(wire.wireStart.nodeId) : undefined;
const wireStart = wireStartNode?.isLayer || false;
const wireEndNode = $nodeGraph.nodes.get((wire.wireEnd as Node).nodeId);
const wireEndNode = wire.wireEnd.nodeId !== undefined ? $nodeGraph.nodes.get(wire.wireEnd.nodeId) : undefined;
const wireEnd = (wireEndNode?.isLayer && Number(wire.wireEnd.index) === 0) || false;
return [createWirePath(nodeOutput, nodeInput, wireStart, wireEnd, wire.dashed)];
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/widgets/buttons/TextButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@
(e.target as HTMLElement | undefined)?.focus();
// Open the menu list floating menu
if (self) {
self.open = true;
} else {
throw new Error("The menu bar floating menu has no associated ref");
}
if (self) self.open = true;
else throw new Error("The menu bar floating menu has no reference to `self`");
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/widgets/inputs/DropdownInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand All @@ -58,7 +58,7 @@
}
function dispatchHoverOutEntry() {
dispatch("hoverOutEntry", initialSelectedIndex);
if (initialSelectedIndex !== undefined) dispatch("hoverOutEntry", initialSelectedIndex);
}
function makeActiveEntry(): MenuListEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/window/title-bar/TitleBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 0 additions & 26 deletions frontend/src/utility-functions/computational-geometry.ts

This file was deleted.

56 changes: 13 additions & 43 deletions frontend/src/wasm-communication/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) }));

Expand Down Expand Up @@ -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;
Expand All @@ -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 });
Expand All @@ -257,7 +227,7 @@ export class FrontendGraphOutput {
readonly resolvedType!: string | undefined;

@CreateInputConnectorArray
readonly connectedTo!: InputConnector[];
connectedTo!: Node[];
}

export class FrontendNode {
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 0 additions & 10 deletions frontend/wasm/tests/web.rs

This file was deleted.

12 changes: 6 additions & 6 deletions website/other/bezier-rs-demos/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion website/other/bezier-rs-demos/package-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions website/other/bezier-rs-demos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 4 additions & 19 deletions website/other/bezier-rs-demos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions website/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<footer>
<hr />
<nav class="balance-text require-polyfill">
<a href="https://github.com/GraphiteEditor/Graphite" class="link not-uppercase">GitHub</a>
<a href="/license" class="link not-uppercase">License</a>
<a href="/logo" class="link not-uppercase">Logo</a>
<a href="/press" class="link not-uppercase">Press</a>
Expand Down

0 comments on commit 1ee5ffb

Please sign in to comment.