From ca339ac0b2cd753301ec69871ff587acf109d956 Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 15 Oct 2025 09:57:14 +0200 Subject: [PATCH] refactor: remove all eslint-disable statements and fix underlying issues - Replace @typescript-eslint/no-explicit-any with proper Filter type from nostr-tools/filter in dataFetch.ts and helpers.ts - Replace @typescript-eslint/no-explicit-any with IAccount and AccountManager types from applesauce-accounts in hooks - Replace @typescript-eslint/no-explicit-any with unknown type casts in App.tsx for keep-alive subscription - Fix react-hooks/exhaustive-deps warnings by including all dependencies in useEffect hooks - Remove unused _settings parameters in useImageCache.ts that were causing no-unused-vars warnings --- src/App.tsx | 10 ++++------ src/components/AddBookmarkModal.tsx | 3 +-- src/components/Bookmarks.tsx | 3 +-- src/hooks/useBookmarksData.ts | 7 +++---- src/hooks/useHighlightCreation.ts | 4 ++-- src/hooks/useImageCache.ts | 10 ++-------- src/services/dataFetch.ts | 4 ++-- src/utils/helpers.ts | 4 ++-- 8 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 68486c89..942b8f20 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -215,8 +215,7 @@ function App() { console.log('🔗 Created keep-alive subscription for', RELAYS.length, 'relay(s)') // Store subscription for cleanup - // eslint-disable-next-line @typescript-eslint/no-explicit-any - ;(pool as any)._keepAliveSubscription = keepAliveSub + ;(pool as unknown as { _keepAliveSubscription: typeof keepAliveSub })._keepAliveSubscription = keepAliveSub // Attach address/replaceable loaders so ProfileModel can fetch profiles const addressLoader = createAddressLoader(pool, { @@ -235,10 +234,9 @@ function App() { accountsSub.unsubscribe() activeSub.unsubscribe() // Clean up keep-alive subscription if it exists - // eslint-disable-next-line @typescript-eslint/no-explicit-any - if ((pool as any)._keepAliveSubscription) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (pool as any)._keepAliveSubscription.unsubscribe() + const poolWithSub = pool as unknown as { _keepAliveSubscription?: { unsubscribe: () => void } } + if (poolWithSub._keepAliveSubscription) { + poolWithSub._keepAliveSubscription.unsubscribe() } } } diff --git a/src/components/AddBookmarkModal.tsx b/src/components/AddBookmarkModal.tsx index 26601351..b5eff9c3 100644 --- a/src/components/AddBookmarkModal.tsx +++ b/src/components/AddBookmarkModal.tsx @@ -140,8 +140,7 @@ const AddBookmarkModal: React.FC = ({ onClose, onSave }) clearTimeout(fetchTimeoutRef.current) } } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [url]) // Only depend on url - title, description, tagsInput are intentionally checked but not dependencies + }, [url, title, description, tagsInput]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() diff --git a/src/components/Bookmarks.tsx b/src/components/Bookmarks.tsx index bddc1d6e..3718f036 100644 --- a/src/components/Bookmarks.tsx +++ b/src/components/Bookmarks.tsx @@ -130,8 +130,7 @@ const Bookmarks: React.FC = ({ relayPool, onLogout }) => { if (isMobile && isSidebarOpen) { toggleSidebar() } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [location.pathname]) + }, [location.pathname, isMobile, isSidebarOpen, toggleSidebar]) // Handle highlight navigation from explore page useEffect(() => { diff --git a/src/hooks/useBookmarksData.ts b/src/hooks/useBookmarksData.ts index 2eb550f4..6505ad6a 100644 --- a/src/hooks/useBookmarksData.ts +++ b/src/hooks/useBookmarksData.ts @@ -1,5 +1,6 @@ import { useState, useEffect, useCallback } from 'react' import { RelayPool } from 'applesauce-relay' +import { IAccount, AccountManager } from 'applesauce-accounts' import { Bookmark } from '../types/bookmarks' import { Highlight } from '../types/highlights' import { fetchBookmarks } from '../services/bookmarkService' @@ -9,10 +10,8 @@ import { UserSettings } from '../services/settingsService' interface UseBookmarksDataParams { relayPool: RelayPool | null - // eslint-disable-next-line @typescript-eslint/no-explicit-any - activeAccount: any - // eslint-disable-next-line @typescript-eslint/no-explicit-any - accountManager: any + activeAccount: IAccount | undefined + accountManager: AccountManager naddr?: string currentArticleCoordinate?: string currentArticleEventId?: string diff --git a/src/hooks/useHighlightCreation.ts b/src/hooks/useHighlightCreation.ts index 2539b8cb..0a9bfafe 100644 --- a/src/hooks/useHighlightCreation.ts +++ b/src/hooks/useHighlightCreation.ts @@ -3,6 +3,7 @@ import { flushSync } from 'react-dom' import { RelayPool } from 'applesauce-relay' import { NostrEvent } from 'nostr-tools' import { IEventStore } from 'applesauce-core' +import { IAccount } from 'applesauce-accounts' import { Highlight } from '../types/highlights' import { ReadableContent } from '../services/readerService' import { createHighlight } from '../services/highlightCreationService' @@ -10,8 +11,7 @@ import { HighlightButtonRef } from '../components/HighlightButton' import { UserSettings } from '../services/settingsService' interface UseHighlightCreationParams { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - activeAccount: any + activeAccount: IAccount | undefined relayPool: RelayPool | null eventStore: IEventStore | null currentArticle: NostrEvent | undefined diff --git a/src/hooks/useImageCache.ts b/src/hooks/useImageCache.ts index f3d52b90..6d93fe41 100644 --- a/src/hooks/useImageCache.ts +++ b/src/hooks/useImageCache.ts @@ -1,5 +1,3 @@ -import { UserSettings } from '../services/settingsService' - /** * Hook to return image URL for display * Service Worker handles all caching transparently @@ -9,9 +7,7 @@ import { UserSettings } from '../services/settingsService' * @returns The image URL (Service Worker handles caching) */ export function useImageCache( - imageUrl: string | undefined, - // eslint-disable-next-line no-unused-vars - _settings?: UserSettings + imageUrl: string | undefined ): string | undefined { // Service Worker handles everything - just return the URL as-is return imageUrl @@ -22,9 +18,7 @@ export function useImageCache( * Triggers a fetch so the SW can cache it even if not visible yet */ export function useCacheImageOnLoad( - imageUrl: string | undefined, - // eslint-disable-next-line no-unused-vars - _settings?: UserSettings + imageUrl: string | undefined ): void { // Service Worker will cache on first fetch // This hook is now a no-op, kept for API compatibility diff --git a/src/services/dataFetch.ts b/src/services/dataFetch.ts index f4f31bb4..011c71d2 100644 --- a/src/services/dataFetch.ts +++ b/src/services/dataFetch.ts @@ -1,6 +1,7 @@ import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay' import { Observable, merge, takeUntil, timer, toArray, tap, lastValueFrom } from 'rxjs' import { NostrEvent } from 'nostr-tools' +import { Filter } from 'nostr-tools/filter' import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers' import { LOCAL_TIMEOUT_MS, REMOTE_TIMEOUT_MS } from '../config/network' @@ -17,8 +18,7 @@ export interface QueryOptions { */ export async function queryEvents( relayPool: RelayPool, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - filter: any, + filter: Filter, options: QueryOptions = {} ): Promise { const { diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 071dac6a..b3fcafa4 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -102,13 +102,13 @@ export const prioritizeLocalRelays = (relayUrls: string[]): string[] => { // Parallel request helper import { completeOnEose, onlyEvents, RelayPool } from 'applesauce-relay' import { Observable, takeUntil, timer } from 'rxjs' +import { Filter } from 'nostr-tools/filter' export function createParallelReqStreams( relayPool: RelayPool, localRelays: string[], remoteRelays: string[], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - filter: any, + filter: Filter, localTimeoutMs = 1200, remoteTimeoutMs = 6000 ): { local$: Observable; remote$: Observable } {