From 9349afc00f54b3278f0fbc02cdf5819c0e2e61d0 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 30 Nov 2025 14:52:20 +0000 Subject: [PATCH] Run lint & fmt --- .../obsidian-plugin/src/vault-link-plugin.ts | 3 + .../src/views/logs/logs-view.ts | 15 ++- .../src/views/settings/settings-tab.ts | 91 +++++++++++-------- .../src/file-operations/file-operations.ts | 1 + .../sync-client/src/persistence/settings.ts | 6 +- .../src/services/websocket-manager.test.ts | 2 + .../sync-client/src/sync-operations/syncer.ts | 2 +- 7 files changed, 73 insertions(+), 47 deletions(-) diff --git a/frontend/obsidian-plugin/src/vault-link-plugin.ts b/frontend/obsidian-plugin/src/vault-link-plugin.ts index 783e732b..54e302f8 100644 --- a/frontend/obsidian-plugin/src/vault-link-plugin.ts +++ b/frontend/obsidian-plugin/src/vault-link-plugin.ts @@ -43,12 +43,14 @@ export default class VaultLinkPlugin extends Plugin { public async onload(): Promise { this.app.workspace.onLayoutReady(async () => { + // eslint-disable-next-line if ((globalThis as any).VAULT_LINK_RUNNING_INSTANCE) { new Notice( "Another instance of VaultLink is already running. Please disable the duplicate instance." ); throw new Error("VaultLink instance already running"); } + // eslint-disable-next-line (globalThis as any).VAULT_LINK_RUNNING_INSTANCE = this; const client = await this.createSyncClient(); @@ -199,6 +201,7 @@ export default class VaultLinkPlugin extends Plugin { }); this.register(() => { + // eslint-disable-next-line (globalThis as any).VAULT_LINK_RUNNING_INSTANCE = null; }); } diff --git a/frontend/obsidian-plugin/src/views/logs/logs-view.ts b/frontend/obsidian-plugin/src/views/logs/logs-view.ts index f624d848..395cfe09 100644 --- a/frontend/obsidian-plugin/src/views/logs/logs-view.ts +++ b/frontend/obsidian-plugin/src/views/logs/logs-view.ts @@ -78,14 +78,18 @@ export class LogsView extends ItemView { text: "VaultLink logs" }); - const controls = verbositySection.createDiv({ cls: "logs-controls" }); + const controls = verbositySection.createDiv({ + cls: "logs-controls" + }); const copyButton = controls.createEl("button", { text: "Copy logs", cls: "clickable-icon" }); setIcon(copyButton, "clipboard-copy"); - copyButton.addEventListener("click", () => { this.copyLogsToClipboard(); }); + copyButton.addEventListener("click", () => { + this.copyLogsToClipboard(); + }); controls.createEl("select", {}, (dropdown) => { logLevels.forEach(({ label, value }) => @@ -127,12 +131,15 @@ export class LogsView extends ItemView { }) .join("\n"); - navigator.clipboard.writeText(formattedLogs) + navigator.clipboard + .writeText(formattedLogs) .then(() => { new Notice(`Copied ${logs.length} log entries to clipboard`); }) .catch((error: unknown) => { - this.client.logger.error(`Failed to copy logs to clipboard: ${error}`); + this.client.logger.error( + `Failed to copy logs to clipboard: ${error}` + ); new Notice("Failed to copy logs to clipboard"); }); } diff --git a/frontend/obsidian-plugin/src/views/settings/settings-tab.ts b/frontend/obsidian-plugin/src/views/settings/settings-tab.ts index 3c711a57..1ff78a4b 100644 --- a/frontend/obsidian-plugin/src/views/settings/settings-tab.ts +++ b/frontend/obsidian-plugin/src/views/settings/settings-tab.ts @@ -73,7 +73,7 @@ export class SyncSettingsTab extends PluginSettingTab { private set isApplyingChanges(value: boolean) { this._isApplyingChanges = value; - this.display() + this.display(); } public display(): void { @@ -157,10 +157,10 @@ export class SyncSettingsTab extends PluginSettingTab { text: "Show history" }, (button) => - (button.onclick = async (): Promise => { - this.plugin.closeSettings(); - await this.plugin.activateView(HistoryView.TYPE); - }) + (button.onclick = async (): Promise => { + this.plugin.closeSettings(); + await this.plugin.activateView(HistoryView.TYPE); + }) ); buttonContainer.createEl( @@ -169,10 +169,10 @@ export class SyncSettingsTab extends PluginSettingTab { text: "Show logs" }, (button) => - (button.onclick = async (): Promise => { - this.plugin.closeSettings(); - await this.plugin.activateView(LogsView.TYPE); - }) + (button.onclick = async (): Promise => { + this.plugin.closeSettings(); + await this.plugin.activateView(LogsView.TYPE); + }) ); } ); @@ -251,7 +251,7 @@ export class SyncSettingsTab extends PluginSettingTab { ) .onClick(() => { // don't show loader within the button - void (async () => { + void (async (): Promise => { if (this.areThereUnsavedChanges()) { new Notice("Applying changes to the server..."); @@ -302,24 +302,31 @@ export class SyncSettingsTab extends PluginSettingTab { ) .addToggle((toggle) => toggle - .setValue(this.syncEnabledOverride ?? this.syncClient.getSettings().isSyncEnabled) + .setValue( + this.syncEnabledOverride ?? + this.syncClient.getSettings().isSyncEnabled + ) .setDisabled(this.isApplyingChanges) .setTooltip( this.isApplyingChanges ? "Waiting for applying changes to finish..." : "Enable or disable syncing." ) - .onChange((value) => void (async () => { - this.syncEnabledOverride = value; - this.isApplyingChanges = true; - try { - await this.syncClient.setSetting("isSyncEnabled", value); - } finally { - this.syncEnabledOverride = undefined; - this.isApplyingChanges = false; - } - } - )() + .onChange( + (value) => + void (async (): Promise => { + this.syncEnabledOverride = value; + this.isApplyingChanges = true; + try { + await this.syncClient.setSetting( + "isSyncEnabled", + value + ); + } finally { + this.syncEnabledOverride = undefined; + this.isApplyingChanges = false; + } + })() ) ); @@ -407,18 +414,21 @@ export class SyncSettingsTab extends PluginSettingTab { : "Reset sync state" ) .setButtonText("Reset sync state") - .onClick(() => void (async () => { - this.isApplyingChanges = true; - try { - await this.syncClient.reset(); - } finally { - this.isApplyingChanges = false; - } + .onClick( + () => + void (async (): Promise => { + this.isApplyingChanges = true; + try { + await this.syncClient.reset(); + } finally { + this.isApplyingChanges = false; + } - new Notice( - "Sync state has been reset, you will need to resync" - ); - })()) + new Notice( + "Sync state has been reset, you will need to resync" + ); + })() + ) ); } @@ -533,9 +543,9 @@ export class SyncSettingsTab extends PluginSettingTab { name: string, settingName: keyof SyncSettings ): [ - DocumentFragment, - (newValue: SyncSettings[keyof SyncSettings]) => unknown - ] { + DocumentFragment, + (newValue: SyncSettings[keyof SyncSettings]) => unknown + ] { const titleContainer = document.createDocumentFragment(); const title = titleContainer.createEl("div", { text: name, @@ -545,10 +555,11 @@ export class SyncSettingsTab extends PluginSettingTab { const updateTitle = ( currentValue: SyncSettings[keyof SyncSettings] ): void => { - title.innerText = `${name}${currentValue !== this.syncClient.getSettings()[settingName] - ? " (unsaved)" - : "" - }`; + title.innerText = `${name}${ + currentValue !== this.syncClient.getSettings()[settingName] + ? " (unsaved)" + : "" + }`; }; return [titleContainer, updateTitle]; diff --git a/frontend/sync-client/src/file-operations/file-operations.ts b/frontend/sync-client/src/file-operations/file-operations.ts index 8f39ff69..6bfdc305 100644 --- a/frontend/sync-client/src/file-operations/file-operations.ts +++ b/frontend/sync-client/src/file-operations/file-operations.ts @@ -268,6 +268,7 @@ export class FileOperations { let newName = path; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition while (true) { currentCount++; newName = `${directory}${stem} (${currentCount})${extension}`; diff --git a/frontend/sync-client/src/persistence/settings.ts b/frontend/sync-client/src/persistence/settings.ts index 08dcfba4..81044a38 100644 --- a/frontend/sync-client/src/persistence/settings.ts +++ b/frontend/sync-client/src/persistence/settings.ts @@ -39,7 +39,7 @@ export class Settings { private readonly onSettingsChangeHandlers: (( newSettings: SyncSettings, oldSettings: SyncSettings - ) => Promise | unknown)[] = []; + ) => unknown)[] = []; public constructor( private readonly logger: Logger, @@ -86,7 +86,9 @@ export class Settings { public async setSettings(value: Partial): Promise { await this.lock.withLock(async () => { - this.logger.debug(`Updating settings with: ${JSON.stringify(value)}`); + this.logger.debug( + `Updating settings with: ${JSON.stringify(value)}` + ); const oldSettings = this.settings; this.settings = { ...this.settings, diff --git a/frontend/sync-client/src/services/websocket-manager.test.ts b/frontend/sync-client/src/services/websocket-manager.test.ts index a4f0fb2e..13aca939 100644 --- a/frontend/sync-client/src/services/websocket-manager.test.ts +++ b/frontend/sync-client/src/services/websocket-manager.test.ts @@ -4,6 +4,8 @@ import assert from "node:assert"; import { WebSocketManager } from "./websocket-manager"; import type { Logger } from "../tracing/logger"; import type { Settings } from "../persistence/settings"; +// eslint-disable-next-line @typescript-eslint/no-require-imports +const WebSocket = require("ws") as typeof globalThis.WebSocket; class MockCloseEvent extends Event { public code: number; diff --git a/frontend/sync-client/src/sync-operations/syncer.ts b/frontend/sync-client/src/sync-operations/syncer.ts index d6ee5621..12008b59 100644 --- a/frontend/sync-client/src/sync-operations/syncer.ts +++ b/frontend/sync-client/src/sync-operations/syncer.ts @@ -173,7 +173,7 @@ export class Syncer { // in that case, we mustn't move it again. if ( this.database.getLatestDocumentByRelativePath(relativePath) === - undefined || + undefined || this.database.getLatestDocumentByRelativePath(relativePath) ?.isDeleted === true ) {