From d4f50dbbefcef78918e293a6bfbbbdcafad737e5 Mon Sep 17 00:00:00 2001 From: mpstaton Date: Sun, 10 May 2026 22:31:06 -0500 Subject: [PATCH] fix(lint): switch Vault.delete() to FileManager.trashFile() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ObsidianReviewBot's `prefer-file-manager-trash-file` is the optional finding it surfaces against image-gin: `Vault.delete()` ignores the user's "Files & links → Move to system trash / Obsidian trash / delete permanently" preference, while `FileManager.trashFile()` respects it. Three sites, all behind explicit user actions (settings toggle or the Clear Cache button), so the deletion-preference is exactly the contract we want to honor. - BatchDirectoryConvertLocalToRemote.ts:449 — local file removal after a successful ImageKit upload, gated by `imageKit.removeLocalFiles` setting. - imageCacheService.ts:156, 164 — `clearCache()` removing the configured cache folder (either as a single TFile or as the contents of a folder). After this commit `pnpm exec eslint .` reports 0 errors and 0 warnings against the obsidianmd recommended config. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/modals/BatchDirectoryConvertLocalToRemote.ts | 2 +- src/services/imageCacheService.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modals/BatchDirectoryConvertLocalToRemote.ts b/src/modals/BatchDirectoryConvertLocalToRemote.ts index 2906e7d..c1a0842 100644 --- a/src/modals/BatchDirectoryConvertLocalToRemote.ts +++ b/src/modals/BatchDirectoryConvertLocalToRemote.ts @@ -446,7 +446,7 @@ export class BatchDirectoryConvertLocalToRemote extends Modal { // Optionally remove local file if setting is enabled if (this.plugin.settings.imageKit.removeLocalFiles) { try { - await this.app.vault.delete(imageFile); + await this.app.fileManager.trashFile(imageFile); } catch (error) { logger.warn(`Could not delete local file ${imageRef.imagePath}:`, error); } diff --git a/src/services/imageCacheService.ts b/src/services/imageCacheService.ts index c664492..c977e92 100644 --- a/src/services/imageCacheService.ts +++ b/src/services/imageCacheService.ts @@ -153,7 +153,7 @@ export class ImageCacheService { const cacheFolder = this.app.vault.getAbstractFileByPath(this.cacheFolder); if (cacheFolder && cacheFolder instanceof TFile) { // If it's a file, delete it - await this.app.vault.delete(cacheFolder); + await this.app.fileManager.trashFile(cacheFolder); } else if (cacheFolder) { // If it's a folder, delete all files in it const files = this.app.vault.getFiles().filter(file => @@ -161,7 +161,7 @@ export class ImageCacheService { ); for (const file of files) { - await this.app.vault.delete(file); + await this.app.fileManager.trashFile(file); } }