fix(lint): switch Vault.delete() to FileManager.trashFile()

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) <noreply@anthropic.com>
This commit is contained in:
mpstaton 2026-05-10 22:31:06 -05:00
parent aa3ddf42e3
commit d4f50dbbef
2 changed files with 3 additions and 3 deletions

View file

@ -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);
}

View file

@ -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);
}
}