Open source personal finance application
refactor: remove redundant comments, fix lint errors and statConfig tests
Ilya Komichev0fcdc3004a02
diff --git a/app/components/amount/getTotal.ts b/app/components/amount/getTotal.tsindex e9c39829..ea79e1c9 100644--- a/app/components/amount/getTotal.ts+++ b/app/components/amount/getTotal.ts@@ -67,7 +67,6 @@ export function getTotal(props: TotalProps): TotalReturns {if (!trn)continue- // Transactionif (trn.type === TrnType.Income || trn.type === TrnType.Expense) {if (trn.categoryId === 'adjustment') {const wallet = walletsItems[trn.walletId]@@ -84,7 +83,6 @@ export function getTotal(props: TotalProps): TotalReturns {expense += sum}- // Transferelse if (trn.type === TrnType.Transfer && 'incomeWalletId' in trn) {const incomeWallet = walletsItems[trn.incomeWalletId]const expenseWallet = walletsItems[trn.expenseWalletId]@@ -94,7 +92,6 @@ export function getTotal(props: TotalProps): TotalReturns {const incomeAmount = getAmount(trn.incomeAmount, incomeWallet.currency)const expenseAmount = getAmount(trn.expenseAmount, expenseWallet.currency)- // Include only selected walletsif (walletsSet) {if (walletsSet.has(trn.incomeWalletId))incomeTransfers += incomeAmount@@ -109,7 +106,6 @@ export function getTotal(props: TotalProps): TotalReturns {}}- // Totalconst sum = income - expenseconst sumTransfers = incomeTransfers - expenseTransfersdiff --git a/app/components/app/useInitApp.ts b/app/components/app/useInitApp.tsindex a800e113..146e29e5 100644--- a/app/components/app/useInitApp.ts+++ b/app/components/app/useInitApp.ts@@ -27,7 +27,6 @@ export function useInitApp() {const categoriesStore = useCategoriesStore()const trnsStore = useTrnsStore()- // Sync data when coming back onlineuseEventListener(window, 'online', () => {isOffline.value = falseif (userStore.uid && !isDbLoading.value)diff --git a/app/components/bottomSheet/BottomSheet.vue b/app/components/bottomSheet/BottomSheet.vueindex 2043d06f..344a7c51 100644--- a/app/components/bottomSheet/BottomSheet.vue+++ b/app/components/bottomSheet/BottomSheet.vue@@ -11,13 +11,11 @@ const emit = defineEmits<{closed: []}>()-// Settingsconst settings = {pixelOffsetToStartClosing: 20,pixelsNeedToDragForClose: 60,}-// Ref Elementsconst drag = ref<HTMLElement | null>(null)const containerRef = ref<HTMLElement | null>(null)const handlerRef = ref<HTMLElement | null>(null)@@ -44,14 +42,8 @@ const {settings,})-/**- * Body scroll lock- */const isBodyLocked = useScrollLock(document.body)-/**- * Run init when mounted or isShow changed- */watch(() => props.isShow,(value) => {@@ -94,7 +86,6 @@ const dragClasses = computed(() => [:class="wrapClasses"class="fixed inset-0 z-50 size-full overflow-hidden select-none">- <!-- Overlay --><div:class="overflowClasses":style="overlayStyles"@@ -102,7 +93,6 @@ const dragClasses = computed(() => [@click="close()"/>- <!-- Drag --><divref="drag":class="dragClasses"diff --git a/app/components/bottomSheet/useBottomSheetDrag.ts b/app/components/bottomSheet/useBottomSheetDrag.tsindex 35891a68..888b6379 100644--- a/app/components/bottomSheet/useBottomSheetDrag.ts+++ b/app/components/bottomSheet/useBottomSheetDrag.ts@@ -223,7 +223,6 @@ export function useBottomSheetDrag({emit('closed')}- // Event listener managementlet stopListeners: (() => void) | null = nullfunction addEvents() {diff --git a/app/components/categories/Name.vue b/app/components/categories/Name.vueindex 010808f8..1d764bf0 100644--- a/app/components/categories/Name.vue+++ b/app/components/categories/Name.vue@@ -14,17 +14,14 @@ const props = defineProps<{<template><div :class="cn('flex gap-3 items-baseline pt-0', props.alt && 'flex-col gap-0.5')">- <!-- Parent category name --><template v-if="alt && isShowParent && !props.hasChildren && props.category?.parentId"><div class="text-2xs text-4 leading-none">{{ props.parentCategory?.name }}</div></template>- <!-- Base name --><div class="text-toned flex items-center gap-2 text-sm leading-none font-medium tracking-wide text-nowrap">{{ props.category?.name }}- <!-- Has childs --><divv-if="props.isShowDots && props.hasChildren"class="text-4 text-xs leading-none"@@ -40,7 +37,6 @@ const props = defineProps<{</div></div>- <!-- Parent category name --><template v-if="!alt && isShowParent && !props.hasChildren && props.category?.parentId"><div class="text-2xs text-4 leading-none text-nowrap">•diff --git a/app/components/categories/useCategoriesStore.test.ts b/app/components/categories/useCategoriesStore.test.tsindex fde8d499..1236398d 100644--- a/app/components/categories/useCategoriesStore.test.ts+++ b/app/components/categories/useCategoriesStore.test.ts@@ -4,8 +4,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { CategoryItem } from '~/components/categories/types'-// --- Entity-specific mocks ----vi.mock('~~/services/convex/api', () => ({convexCategoriesToMap: (v: any) => v,}))@@ -54,8 +52,6 @@ vi.mock('~/components/offline/helpers', async (importOriginal) => {const { useCategoriesStore } = await import('~/components/categories/useCategoriesStore')-// --- Helpers ----function makeCategory(overrides: Partial<CategoryItem> = {}): CategoryItem {return {color: '#f00',@@ -68,8 +64,6 @@ function makeCategory(overrides: Partial<CategoryItem> = {}): CategoryItem {}}-// --- Tests ----describe('useCategoriesStore', () => {beforeEach(async () => {setActivePinia(createPinia())diff --git a/app/components/currencies/useCurrenciesStore.ts b/app/components/currencies/useCurrenciesStore.tsindex c3d81d1b..52cdb5c7 100644--- a/app/components/currencies/useCurrenciesStore.ts+++ b/app/components/currencies/useCurrenciesStore.ts@@ -21,7 +21,6 @@ export const useCurrenciesStore = defineStore('currencies', () => {try {const { api, client } = useConvexClientWithApi()- // Get latest rates from Convexconst latestRates = await client.query(api.rates.getLatest, {})if (latestRates?.rates) {diff --git a/app/components/date/statDateParams.test.ts b/app/components/date/statDateParams.test.tsindex e26d979e..8688b57c 100644--- a/app/components/date/statDateParams.test.ts+++ b/app/components/date/statDateParams.test.ts@@ -4,8 +4,6 @@ import type { Range, StatDateParams } from '~/components/date/types'import { computeDateRange, defaultStatDateParams, parseStatDateQueryParams } from './statDateParams'-// --- parseStatDateQueryParams ----describe('parseStatDateQueryParams', () => {const base: StatDateParams = { ...defaultStatDateParams }@@ -88,8 +86,6 @@ describe('parseStatDateQueryParams', () => {})})-// --- computeDateRange ----describe('computeDateRange', () => {const now = new Date('2024-06-15T12:00:00').getTime()const maxRange: Range = {@@ -133,7 +129,6 @@ describe('computeDateRange', () => {const result = computeDateRange(params, maxRange, now)expect(result.start).toBe(maxRange.start)- // end should be end of current month, not maxRange.endexpect(result.end).toBeGreaterThanOrEqual(now)})@@ -168,7 +163,6 @@ describe('computeDateRange', () => {const range0 = computeDateRange(params0, maxRange, now)const range1 = computeDateRange(params1, maxRange, now)- // positive offset subtracts time (goes back)expect(range1.start).toBeLessThan(range0.start)expect(range1.end).toBeLessThan(range0.end)})@@ -190,8 +184,6 @@ describe('computeDateRange', () => {})})-// --- defaultStatDateParams ----describe('defaultStatDateParams', () => {it('has expected defaults', () => {expect(defaultStatDateParams.customDate).toBe(false)diff --git a/app/components/date/utils.ts b/app/components/date/utils.tsindex acfeaa4c..2d395af0 100644--- a/app/components/date/utils.ts+++ b/app/components/date/utils.ts@@ -1,7 +1,7 @@import type { CalendarDate } from '@internationalized/date'+import type { Duration } from 'date-fns'import { getLocalTimeZone, parseDate, today } from '@internationalized/date'-import type { Duration } from 'date-fns'import { differenceInDays, endOfDay, endOfMonth, endOfWeek, endOfYear, format, formatISO, startOfDay, startOfMonth, startOfWeek, startOfYear, sub } from 'date-fns'import { ru } from 'date-fns/locale'diff --git a/app/components/layout/MenuBottomModal.vue b/app/components/layout/MenuBottomModal.vueindex f005c8dd..9c3f3d19 100644--- a/app/components/layout/MenuBottomModal.vue+++ b/app/components/layout/MenuBottomModal.vue@@ -21,7 +21,6 @@ const { isDemo } = useDemo()<div class="bottomSheetContent"><div class="bottomSheetContentInside px-3 pt-4 pb-2">- <!-- User --><divv-if="!isDemo"class="border-item-6 mx-2 border-b pt-2 pb-2"diff --git a/app/components/layout/Sidebar.vue b/app/components/layout/Sidebar.vueindex eccdaa7a..956e545d 100644--- a/app/components/layout/Sidebar.vue+++ b/app/components/layout/Sidebar.vue@@ -31,7 +31,6 @@ const { getWalletContextMenuItems } = useWalletContextMenu()class="fixed inset-y-0 left-0 z-40 hidden h-dvh w-12 overflow-hidden transition-all duration-300 ease-in-out sm:block"><div class="relative h-full overflow-hidden overflow-y-auto overscroll-contain">- <!-- Small menu --><LayoutSidebarMenu:isShowText="false":class="{ 'md:hidden': props.isShowSidebar }"diff --git a/app/components/offline/helpers.test.ts b/app/components/offline/helpers.test.tsindex 16adaca1..b90ebedd 100644--- a/app/components/offline/helpers.test.ts+++ b/app/components/offline/helpers.test.ts@@ -10,7 +10,6 @@ import {} from '~/components/offline/helpers'import { OfflineEntityType } from '~/components/offline/types'-// Mock localforageconst store = new Map<string, any>()vi.mock('localforage', () => ({@@ -186,7 +185,6 @@ describe('cross-entity isolation', () => {await pushOfflineOp({ entity: OfflineEntityType.Trns, id: 'id1', type: 'delete' })const queue = await getAllOfflineOps()- // trns create+delete collapsed to nothing, wallets create remainsexpect(queue).toHaveLength(1)expect(queue[0]!.entity).toBe(OfflineEntityType.Wallets)})diff --git a/app/components/stat/chart/config.ts b/app/components/stat/chart/config.tsindex 7c1ed087..beabda89 100644--- a/app/components/stat/chart/config.ts+++ b/app/components/stat/chart/config.ts@@ -30,7 +30,6 @@ export const seriesOptions: Record<SeriesSlug, SeriesOption> = {}export const config: EChartsOption['baseOption'] = {- // Gridgrid: {bottom: '0',containLabel: true,@@ -39,7 +38,6 @@ export const config: EChartsOption['baseOption'] = {top: '5',},- // Tooltiptooltip: {axisPointer: {animation: false,@@ -51,7 +49,6 @@ export const config: EChartsOption['baseOption'] = {trigger: 'axis',},- // xAxisxAxis: {axisLabel: {color: 'var(--chart-label)',@@ -75,12 +72,11 @@ export const config: EChartsOption['baseOption'] = {type: 'category',},- // yAxisyAxis: {axisLabel: {color: 'var(--chart-label)',formatter: (n: number) => formatCompactChartAmount(n),- show: false, // TODO: config+ show: false,},axisLine: {lineStyle: {diff --git a/app/components/stat/filter/Selected.vue b/app/components/stat/filter/Selected.vueindex 37ebaff6..4ed73e20 100644--- a/app/components/stat/filter/Selected.vue+++ b/app/components/stat/filter/Selected.vue@@ -16,7 +16,6 @@ const itemClasses = 'bg-item-3 rounded-sm'<template><div class="flex gap-2">- <!-- Wallets --><template v-if="props.isShowWallets"><WalletsItemv-for="walletId in filter?.walletsIds?.value"@@ -31,7 +30,6 @@ const itemClasses = 'bg-item-3 rounded-sm'/></template>- <!-- Categories --><template v-if="props.isShowCategories"><CategoriesItemv-for="categoryId in filter?.categoriesIds?.value"diff --git a/app/components/stat/statConfig.test.ts b/app/components/stat/statConfig.test.tsindex 41c0c5af..84227e49 100644--- a/app/components/stat/statConfig.test.ts+++ b/app/components/stat/statConfig.test.ts@@ -33,6 +33,9 @@ const defaultConfig: MiniItemConfig = {count: 10,isShow: false,},+ trns: {+ isShow: true,+ },vertical: {isGrouped: false,isShow: false,diff --git a/app/components/trnForm/main/Input.vue b/app/components/trnForm/main/Input.vueindex 42f81746..3b81ee22 100644--- a/app/components/trnForm/main/Input.vue+++ b/app/components/trnForm/main/Input.vue@@ -16,7 +16,6 @@ const { t } = useI18n()<template><div class="relative">- <!-- Sum --><div:class="[{'opacity-0': !isShowSum,diff --git a/app/components/trns/types.ts b/app/components/trns/types.tsindex 58584e86..3bbf6a46 100644--- a/app/components/trns/types.ts+++ b/app/components/trns/types.ts@@ -71,8 +71,8 @@ export type Trns = Record<TrnId, TrnItem>export type TrnsGetterProps = {categoriesIds?: CategoryId[]dates?: {- start: numberend: number+ start: number}sort?: booleantrnsIds?: TrnId[]diff --git a/app/composables/useStoreSync.test.ts b/app/composables/useStoreSync.test.tsindex 35abc192..384351a8 100644--- a/app/composables/useStoreSync.test.ts+++ b/app/composables/useStoreSync.test.ts@@ -3,9 +3,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'import type { OfflineOp } from '~/components/offline/types'-// ----------------------------------------------------------------------------// Mocks — entity-specific (offline helpers)-// ---------------------------------------------------------------------------const getOfflineOpsByEntityMock = vi.fn<() => Promise<OfflineOp[]>>().mockResolvedValue([])const pushOfflineOpMock = vi.fn()const removeOfflineOpMock = vi.fn().mockResolvedValue(undefined)@@ -29,9 +26,6 @@ beforeEach(async () => {await localforage.clear()})-// ----------------------------------------------------------------------------// mergeOfflineOps-// ---------------------------------------------------------------------------describe('mergeOfflineOps', () => {it('applies pending updates and deletes on top of server data', async () => {const { mergeOfflineOps } = await import('~/composables/useStoreSync')@@ -49,11 +43,8 @@ describe('mergeOfflineOps', () => {const result = await mergeOfflineOps(serverData, 'wallets')- // w1 overwritten with pending update dataexpect(result.w1).toEqual({ name: 'Updated' })- // w2 deletedexpect(result).not.toHaveProperty('w2')- // w3 unchangedexpect(result.w3).toEqual({ color: '#aaa', name: 'Untouched' })})@@ -71,7 +62,6 @@ describe('mergeOfflineOps', () => {it('removes stale local_ IDs not in pending queue', async () => {const { mergeOfflineOps } = await import('~/composables/useStoreSync')- // No pending ops for local_stalegetOfflineOpsByEntityMock.mockResolvedValueOnce([{ data: { name: 'New' }, entity: 'wallets', id: 'local_fresh', timestamp: 1, type: 'create' },] satisfies OfflineOp[])@@ -90,9 +80,6 @@ describe('mergeOfflineOps', () => {})})-// ----------------------------------------------------------------------------// handleMutationResult — ID remap-// ---------------------------------------------------------------------------describe('handleMutationResult', () => {it('remaps local_id → convexId on successful create', async () => {const { handleMutationResult, unblockPersist } = await import('~/composables/useStoreSync')@@ -112,15 +99,11 @@ describe('handleMutationResult', () => {mutation: Promise.resolve('convex_w1'),})- // local_abc replaced with convex_w1expect(items.value).not.toHaveProperty('local_abc')expect(items.value).toHaveProperty('convex_w1')expect(items.value!.convex_w1).toEqual({ name: 'Cash' })- // existing untouchedexpect(items.value).toHaveProperty('existing')- // returns remap infoexpect(remap).toEqual({ convexId: 'convex_w1', localId: 'local_abc' })- // persisted to localforageexpect(await localforage.getItem('finapp.wallets')).toEqual(items.value)})@@ -141,12 +124,9 @@ describe('handleMutationResult', () => {mutation: Promise.resolve('convex_w1'),})- // Remap still happensexpect(items.value).toHaveProperty('convex_w1')- // But not persistedexpect(await localforage.getItem('finapp.wallets')).toBeNull()- // Cleanupconst { unblockPersist } = await import('~/composables/useStoreSync')unblockPersist()})@@ -164,11 +144,9 @@ describe('handleMutationResult', () => {mutation: Promise.reject(new Error('network')),})- // Toast shown with error colorexpect(toastAddMock).toHaveBeenCalledWith(expect.objectContaining({ color: 'error' }),)- // Offline op NOT removed (so it can be retried)expect(removeOfflineOpMock).not.toHaveBeenCalled()})@@ -189,9 +167,6 @@ describe('handleMutationResult', () => {})})-// ----------------------------------------------------------------------------// pushSaveOp / pushDeleteOp-// ---------------------------------------------------------------------------describe('pushSaveOp', () => {it('does nothing in demo mode', async () => {const { pushSaveOp } = await import('~/composables/useStoreSync')diff --git a/app/middleware/auth.global.test.ts b/app/middleware/auth.global.test.tsindex d485ff47..ed6f959c 100644--- a/app/middleware/auth.global.test.ts+++ b/app/middleware/auth.global.test.ts@@ -1,8 +1,5 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-// ----------------------------------------------------------------------------// Shared mock state (hoisted so vi.mock factories can reference them)-// ---------------------------------------------------------------------------const {clearAuthCookieMock,getSessionMock,@@ -31,9 +28,6 @@ const {}})-// ----------------------------------------------------------------------------// Module mocks-// ---------------------------------------------------------------------------vi.mock('~/components/demo/useDemo', () => ({useDemo: () => ({ isDemo: isDemoRef }),}))@@ -50,9 +44,6 @@ vi.mock('~/utils/logger', () => ({createLogger: () => ({ error: vi.fn(), info: vi.fn(), warn: vi.fn() }),}))-// ----------------------------------------------------------------------------// Nuxt auto-import stubs-// ---------------------------------------------------------------------------vi.stubGlobal('defineNuxtRouteMiddleware', (fn: any) => fn)vi.stubGlobal('navigateTo', navigateToMock)vi.stubGlobal('navigator', { onLine: true })@@ -63,9 +54,6 @@ vi.stubGlobal('getSafeRedirectPath', (value: unknown) => {return '/dashboard'})-// ----------------------------------------------------------------------------// Helpers-// ---------------------------------------------------------------------------function createRoute(path: string, query: Record<string, string> = {}) {const qs = Object.entries(query).map(([k, v]) => `${k}=${v}`).join('&')return { fullPath: qs ? `${path}?${qs}` : path, path, query }@@ -87,11 +75,6 @@ async function loadMiddleware(): Promise<MiddlewareFn> {return middleware}-// ----------------------------------------------------------------------------// Tests-// ----------------------------------------------------------------------------// SPA mode — all code paths are client-side.-describe('auth.global middleware', () => {beforeEach(() => {vi.clearAllMocks()@@ -100,8 +83,6 @@ describe('auth.global middleware', () => {hasAuthCookieMock.mockReturnValue(false)})- // --- OTT handling ----describe('oTT handling', () => {it('redirects OTT from arbitrary path to /auth/callback', async () => {const middleware = await loadMiddleware()@@ -122,8 +103,6 @@ describe('auth.global middleware', () => {})})- // --- /auth/callback passthrough ----describe('/auth/callback passthrough', () => {it('skips all auth checks', async () => {const middleware = await loadMiddleware()@@ -135,8 +114,6 @@ describe('auth.global middleware', () => {})})- // --- Demo mode ----describe('demo mode', () => {beforeEach(() => {isDemoRef.value = true@@ -165,8 +142,6 @@ describe('auth.global middleware', () => {})})- // --- Client: with auth cookie ----describe('client: with auth cookie', () => {beforeEach(() => {hasAuthCookieMock.mockReturnValue(true)@@ -217,13 +192,11 @@ describe('auth.global middleware', () => {getSessionMock.mockResolvedValueOnce({ data: { user: null } })const middleware = await loadMiddleware()- // First visit: session expired → clearCookie + redirectawait middleware(createRoute('/dashboard'))await flushPromises()expect(clearAuthCookieMock).toHaveBeenCalled()expect(getSessionMock).toHaveBeenCalledOnce()- // Simulate re-login: cookie is back, next navigation should call getSession againgetSessionMock.mockResolvedValue({ data: { user: { id: 'u2' } } })await middleware(createRoute('/settings'))@@ -234,12 +207,10 @@ describe('auth.global middleware', () => {getSessionMock.mockRejectedValueOnce(new Error('network'))const middleware = await loadMiddleware()- // First call: getSession failsawait middleware(createRoute('/dashboard'))await flushPromises()expect(getSessionMock).toHaveBeenCalledOnce()- // Second call: sessionInitialized was reset, so getSession fires againgetSessionMock.mockResolvedValue({ data: { user: { id: 'u1' } } })await middleware(createRoute('/settings'))@@ -247,8 +218,6 @@ describe('auth.global middleware', () => {})})- // --- Client: no auth cookie ----describe('client: no auth cookie', () => {it('passes through /login without verification', async () => {const middleware = await loadMiddleware()@@ -303,8 +272,6 @@ describe('auth.global middleware', () => {})})- // --- Offline scenarios ----describe('offline', () => {beforeEach(() => {vi.stubGlobal('navigator', { onLine: false })diff --git a/app/test-utils/setup-store.ts b/app/test-utils/setup-store.tsindex 9fd1564c..057b1a37 100644--- a/app/test-utils/setup-store.ts+++ b/app/test-utils/setup-store.ts@@ -17,14 +17,8 @@ vi.stubGlobal('shallowRef', shallowRef)vi.stubGlobal('watch', watch)vi.stubGlobal('defineStore', defineStore)-// ----------------------------------------------------------------------------// 2. VueUse auto-imports — synchronous for test predictability-// ---------------------------------------------------------------------------vi.stubGlobal('useDebounceFn', (fn: (...args: any[]) => any) => fn)-// ----------------------------------------------------------------------------// 3. Nuxt auto-imports-// ---------------------------------------------------------------------------export const toastAddMock = vi.fn()vi.stubGlobal('useToast', () => ({ add: toastAddMock }))@@ -32,9 +26,6 @@ vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))vi.stubGlobal('useNuxtApp', () => ({ $i18n: { t: (key: string) => key } }))vi.stubGlobal('tryUseNuxtApp', () => ({ $i18n: { t: (key: string) => key } }))-// ----------------------------------------------------------------------------// 4. Project auto-imports (utils/)-// ---------------------------------------------------------------------------vi.stubGlobal('asConvexId', (id: string) => id)vi.stubGlobal('isLocalId', (id: string) => id.startsWith('local_'))vi.stubGlobal('cleanupFrontendIds', <T>(data: Record<string, T>, pendingUpdates: Record<string, T>) => {@@ -46,9 +37,6 @@ vi.stubGlobal('cleanupFrontendIds', <T>(data: Record<string, T>, pendingUpdates:return result})-// ----------------------------------------------------------------------------// 5. Common module mocks-// ---------------------------------------------------------------------------vi.mock('~/components/demo/useDemo', () => ({useDemo: () => ({ isDemo: { value: false } }),}))diff --git a/nuxt.config.ts b/nuxt.config.tsindex cdfa89bf..aff0063a 100644--- a/nuxt.config.ts+++ b/nuxt.config.ts@@ -28,10 +28,6 @@ export default defineNuxtConfig({},},- experimental: {- // viewTransition: true,- },-fonts: {defaults: {subsets: ['cyrillic', 'latin', 'latin-ext'],