Restore ESLint and Prettier auto-formatting and CI linting (#1457)

* Restore ESLint and Prettier autoformatting

* Fix formatting and lints in web files

* Hacky fix to eslint crash

* Fix remaining lints

* Add lint-fix script

---------

Co-authored-by: 0hypercube <0hypercube@gmail.com>
This commit is contained in:
Keavon Chambers
2023-11-16 13:12:47 -08:00
committed by GitHub
co-authored by 0hypercube
parent 9784d31edb
commit a6ca43bb2d
63 changed files with 5869 additions and 351 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
import { imageToPNG } from "@graphite/utility-functions/rasterization";
import { type Editor } from "@graphite/wasm-communication/editor";
import { TriggerTextCopy } from "@graphite/wasm-communication/messages";
import { imageToPNG } from "@graphite/utility-functions/rasterization";
export function createClipboardManager(editor: Editor): void {
export function createClipboardManager(editor: Editor) {
// Subscribe to process backend event
editor.subscriptions.subscribeJsMessage(TriggerTextCopy, (triggerTextCopy) => {
// If the Clipboard API is supported in the browser, copy text to the clipboard
@@ -10,7 +10,7 @@ export function createClipboardManager(editor: Editor): void {
});
}
export async function copyToClipboardFileURL(url: string): Promise<void> {
export async function copyToClipboardFileURL(url: string) {
const response = await fetch(url);
const blob = await response.blob();
+2 -2
View File
@@ -1,7 +1,7 @@
let draggingElement: HTMLElement | undefined;
export function createDragManager(): () => void {
const clearDraggingElement = (): void => {
const clearDraggingElement = () => {
draggingElement = undefined;
};
@@ -17,7 +17,7 @@ export function createDragManager(): () => void {
};
}
export function beginDraggingElement(element: HTMLElement): void {
export function beginDraggingElement(element: HTMLElement) {
draggingElement = element;
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { type Editor } from "@graphite/wasm-communication/editor";
import { TriggerVisitLink } from "@graphite/wasm-communication/messages";
export function createHyperlinkManager(editor: Editor): void {
export function createHyperlinkManager(editor: Editor) {
// Subscribe to process backend event
editor.subscriptions.subscribeJsMessage(TriggerVisitLink, async (triggerOpenLink) => {
window.open(triggerOpenLink.url, "_blank");
+21 -21
View File
@@ -41,18 +41,18 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
{ target: window, eventName: "wheel", action: (e: WheelEvent) => onWheelScroll(e), options: { passive: false } },
{ target: window, eventName: "modifyinputfield", action: (e: CustomEvent) => onModifyInputField(e) },
{ target: window, eventName: "focusout", action: () => (canvasFocused = false) },
{ target: window.document, eventName: "contextmenu", action: (e: MouseEvent) => onContextMenu(e) },
{ target: window.document, eventName: "contextmenu", action: (e: MouseEvent) => onContextMenu(e) },
{ target: window.document, eventName: "fullscreenchange", action: () => fullscreen.fullscreenModeChanged() },
{ target: window.document.body, eventName: "paste", action: (e: ClipboardEvent) => onPaste(e) },
];
// Event bindings
function bindListeners(): void {
function bindListeners() {
// Add event bindings for the lifetime of the application
listeners.forEach(({ target, eventName, action, options }) => target.addEventListener(eventName, action, options));
}
function unbindListeners(): void {
function unbindListeners() {
// Remove event bindings after the lifetime of the application (or on hot-module replacement during development)
listeners.forEach(({ target, eventName, action, options }) => target.removeEventListener(eventName, action, options));
}
@@ -96,7 +96,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
return true;
}
async function onKeyDown(e: KeyboardEvent): Promise<void> {
async function onKeyDown(e: KeyboardEvent) {
const key = await getLocalizedScanCode(e);
const NO_KEY_REPEAT_MODIFIER_KEYS = ["ControlLeft", "ControlRight", "ShiftLeft", "ShiftRight", "MetaLeft", "MetaRight", "AltLeft", "AltRight", "AltGraph", "CapsLock", "Fn", "FnLock"];
@@ -114,7 +114,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
}
}
async function onKeyUp(e: KeyboardEvent): Promise<void> {
async function onKeyUp(e: KeyboardEvent) {
const key = await getLocalizedScanCode(e);
if (await shouldRedirectKeyboardEventToBackend(e)) {
@@ -127,7 +127,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
// Pointer events
// While any pointer button is already down, additional button down events are not reported, but they are sent as `pointermove` events and these are handled in the backend
function onPointerMove(e: PointerEvent): void {
function onPointerMove(e: PointerEvent) {
if (!e.buttons) viewportPointerInteractionOngoing = false;
// Don't redirect pointer movement to the backend if there's no ongoing interaction and it's over a floating menu, or the graph overlay, on top of the canvas
@@ -149,12 +149,12 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
editor.instance.onMouseMove(e.clientX, e.clientY, e.buttons, modifiers);
}
function onMouseDown(e: MouseEvent): void {
function onMouseDown(e: MouseEvent) {
// Block middle mouse button auto-scroll mode (the circlar gizmo that appears and allows quick scrolling by moving the cursor above or below it)
if (e.button === 1) e.preventDefault();
}
function onPointerDown(e: PointerEvent): void {
function onPointerDown(e: PointerEvent) {
const { target } = e;
const isTargetingCanvas = target instanceof Element && target.closest("[data-viewport]");
const inDialog = target instanceof Element && target.closest("[data-dialog-modal] [data-floating-menu-content]");
@@ -177,7 +177,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
}
}
function onPointerUp(e: PointerEvent): void {
function onPointerUp(e: PointerEvent) {
if (!e.buttons) viewportPointerInteractionOngoing = false;
if (textToolInteractiveInputElement) return;
@@ -186,12 +186,12 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
editor.instance.onMouseUp(e.clientX, e.clientY, e.buttons, modifiers);
}
function onPotentialDoubleClick(e: MouseEvent): void {
function onPotentialDoubleClick(e: MouseEvent) {
if (textToolInteractiveInputElement) return;
// Allow only double-clicks
if (e.detail !== 2) return;
// `e.buttons` is always 0 in the `mouseup` event, so we have to convert from `e.button` instead
let buttons = 1;
if (e.button === 0) buttons = 1; // LMB
@@ -204,7 +204,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
// Mouse events
function onWheelScroll(e: WheelEvent): void {
function onWheelScroll(e: WheelEvent) {
const { target } = e;
const isTargetingCanvas = target instanceof Element && target.closest("[data-viewport]");
@@ -223,7 +223,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
}
}
function onContextMenu(e: MouseEvent): void {
function onContextMenu(e: MouseEvent) {
if (!targetIsTextField(e.target || undefined) && e.target !== textToolInteractiveInputElement) {
e.preventDefault();
}
@@ -231,13 +231,13 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
// Receives a custom event dispatched when the user begins interactively editing with the text tool.
// We keep a copy of the text input element to check against when it's active for text entry.
function onModifyInputField(e: CustomEvent): void {
function onModifyInputField(e: CustomEvent) {
textToolInteractiveInputElement = e.detail;
}
// Window events
function onWindowResize(container: HTMLElement): void {
function onWindowResize(container: HTMLElement) {
const viewports = Array.from(container.querySelectorAll("[data-viewport]"));
const boundsOfViewports = viewports.map((canvas) => {
const bounds = canvas.getBoundingClientRect();
@@ -250,7 +250,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
if (boundsOfViewports.length > 0) editor.instance.boundsOfViewports(data);
}
async function onBeforeUnload(e: BeforeUnloadEvent): Promise<void> {
async function onBeforeUnload(e: BeforeUnloadEvent) {
const activeDocument = get(portfolio).documents[get(portfolio).activeDocumentIndex];
if (activeDocument && !activeDocument.isAutoSaved) editor.instance.triggerAutoSave(activeDocument.id);
@@ -267,7 +267,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
}
}
function onPaste(e: ClipboardEvent): void {
function onPaste(e: ClipboardEvent) {
const dataTransfer = e.clipboardData;
if (!dataTransfer || targetIsTextField(e.target || undefined)) return;
e.preventDefault();
@@ -285,7 +285,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
const file = item.getAsFile();
if (file?.type.startsWith("image")) {
extractPixelData(file).then((imageData): void => {
extractPixelData(file).then((imageData) => {
editor.instance.pasteImage(new Uint8Array(imageData.data), imageData.width, imageData.height);
});
}
@@ -315,7 +315,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
if (item.types.includes("text/plain")) {
const blob = await item.getType("text/plain");
const reader = new FileReader();
reader.onload = (): void => {
reader.onload = () => {
const text = reader.result as string;
if (text.startsWith("graphite/layer: ")) {
@@ -330,7 +330,7 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli
if (imageType) {
const blob = await item.getType(imageType);
const reader = new FileReader();
reader.onload = async (): Promise<void> => {
reader.onload = async () => {
if (reader.result instanceof ArrayBuffer) {
const imageData = await extractPixelData(new Blob([reader.result], { type: imageType }));
editor.instance.pasteImage(new Uint8Array(imageData.data), imageData.width, imageData.height);
+2 -2
View File
@@ -1,8 +1,8 @@
import { type Editor } from "@graphite/wasm-communication/editor";
import { TriggerAboutGraphiteLocalizedCommitDate } from "@graphite/wasm-communication/messages";
export function createLocalizationManager(editor: Editor): void {
function localizeTimestamp(utc: string): { timestamp: string, year: string } {
export function createLocalizationManager(editor: Editor) {
function localizeTimestamp(utc: string): { timestamp: string; year: string } {
// Timestamp
const date = new Date(utc);
if (Number.isNaN(date.getTime())) return { timestamp: utc, year: `${new Date().getFullYear()}` };
+1 -1
View File
@@ -4,7 +4,7 @@ import { stripIndents } from "@graphite/utility-functions/strip-indents";
import { type Editor } from "@graphite/wasm-communication/editor";
import { DisplayDialogPanic } from "@graphite/wasm-communication/messages";
export function createPanicManager(editor: Editor, dialogState: DialogState): void {
export function createPanicManager(editor: Editor, dialogState: DialogState) {
// Code panic dialog and console error
editor.subscriptions.subscribeJsMessage(DisplayDialogPanic, (displayDialogPanic) => {
// `Error.stackTraceLimit` is only available in V8/Chromium
+10 -10
View File
@@ -7,16 +7,16 @@ import { TriggerIndexedDbWriteDocument, TriggerIndexedDbRemoveDocument, TriggerS
const graphiteStore = createStore("graphite", "store");
export function createPersistenceManager(editor: Editor, portfolio: PortfolioState): void {
export function createPersistenceManager(editor: Editor, portfolio: PortfolioState) {
// DOCUMENTS
async function storeDocumentOrder(): Promise<void> {
async function storeDocumentOrder() {
const documentOrder = getFromStore(portfolio).documents.map((doc) => String(doc.id));
await set("documents_tab_order", documentOrder, graphiteStore);
}
async function storeDocument(autoSaveDocument: TriggerIndexedDbWriteDocument): Promise<void> {
async function storeDocument(autoSaveDocument: TriggerIndexedDbWriteDocument) {
await update<Record<string, TriggerIndexedDbWriteDocument>>(
"documents",
(old) => {
@@ -24,13 +24,13 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
documents[autoSaveDocument.details.id] = autoSaveDocument;
return documents;
},
graphiteStore
graphiteStore,
);
await storeDocumentOrder();
}
async function removeDocument(id: string): Promise<void> {
async function removeDocument(id: string) {
await update<Record<string, TriggerIndexedDbWriteDocument>>(
"documents",
(old) => {
@@ -38,13 +38,13 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
delete documents[id];
return documents;
},
graphiteStore
graphiteStore,
);
await storeDocumentOrder();
}
async function loadDocuments(): Promise<void> {
async function loadDocuments() {
const previouslySavedDocuments = await get<Record<string, TriggerIndexedDbWriteDocument>>("documents", graphiteStore);
const documentOrder = await get<string[]>("documents_tab_order", graphiteStore);
if (!previouslySavedDocuments || !documentOrder) return;
@@ -64,11 +64,11 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
// PREFERENCES
async function savePreferences(preferences: TriggerSavePreferences["preferences"]): Promise<void> {
async function savePreferences(preferences: TriggerSavePreferences["preferences"]) {
await set("preferences", preferences, graphiteStore);
}
async function loadPreferences(): Promise<void> {
async function loadPreferences() {
const preferences = await get<Record<string, unknown>>("preferences", graphiteStore);
if (!preferences) return;
@@ -95,7 +95,7 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
});
}
export async function wipeDocuments(): Promise<void> {
export async function wipeDocuments() {
await del("documents_tab_order", graphiteStore);
await del("documents", graphiteStore);
}