From dbc775aa542d2790c91dff64aa8fb35febe504eb Mon Sep 17 00:00:00 2001 From: James Meng Date: Fri, 18 Oct 2024 14:28:21 -0700 Subject: [PATCH] Update with no ESlint rules --- .../theme/src/cli/utilities/theme-fs.test.ts | 2 +- packages/theme/src/cli/utilities/theme-fs.ts | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/theme/src/cli/utilities/theme-fs.test.ts b/packages/theme/src/cli/utilities/theme-fs.test.ts index 87c00e284b..8491342b28 100644 --- a/packages/theme/src/cli/utilities/theme-fs.test.ts +++ b/packages/theme/src/cli/utilities/theme-fs.test.ts @@ -293,7 +293,7 @@ describe('theme-fs', () => { // When const content = await readThemeFile(root, key) - const contentJson = JSON.parse(content?.toString() || '') + const contentJson = JSON.parse(content?.toString() ?? '') // Then expect(contentJson).toEqual({ diff --git a/packages/theme/src/cli/utilities/theme-fs.ts b/packages/theme/src/cli/utilities/theme-fs.ts index 03414db2bb..53da5f8070 100644 --- a/packages/theme/src/cli/utilities/theme-fs.ts +++ b/packages/theme/src/cli/utilities/theme-fs.ts @@ -99,13 +99,16 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti .then(() => { switch (eventName) { case 'add': - case 'change': - return handleFileUpdate(eventName, themeId, adminSession, fileKey) - case 'unlink': - return handleFileDelete(themeId, adminSession, fileKey) + case 'change': { + handleFileUpdate(eventName, themeId, adminSession, fileKey) + return + } + case 'unlink': { + handleFileDelete(themeId, adminSession, fileKey) + } } }) - .catch((error) => { + .catch((error: unknown) => { outputWarn(`Error handling file event for ${fileKey}: ${error}`) }) } @@ -125,14 +128,14 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti const previousChecksum = files.get(fileKey)?.checksum const contentPromise = read(fileKey).then(async () => { - const file = files.get(fileKey)! + const file = files.get(fileKey) - if (file.checksum !== previousChecksum) { + if (file?.checksum !== previousChecksum) { // Sync only if the file has changed unsyncedFileKeys.add(fileKey) } - return file.value || file.attachment || '' + return file?.value ?? file?.attachment ?? '' }) const syncPromise = contentPromise @@ -154,6 +157,7 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti return true }) + // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable .catch(createSyncingCatchError(fileKey, 'upload')) emitEvent(eventName, { @@ -203,8 +207,8 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti outputSyncResult('delete', fileKey) return true }) - .catch((error) => { - createSyncingCatchError(fileKey, 'delete')(error) + .catch((error: unknown) => { + createSyncingCatchError(fileKey, 'delete')(error as Error) return false })