From 1f5b342d8ee5503dac832f9a57b62fa7b20000ad Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Tue, 20 Jan 2026 19:37:49 +0100 Subject: [PATCH] cleanup --- FORMATTER_REPLACEMENT_SUMMARY.md | 300 ------------------------------- TODO_cleanup.md | 138 -------------- dove.svg | 57 ------ extract_crown.py | 38 ---- wine_glass.svg | 11 -- 5 files changed, 544 deletions(-) delete mode 100644 FORMATTER_REPLACEMENT_SUMMARY.md delete mode 100644 TODO_cleanup.md delete mode 100644 dove.svg delete mode 100644 extract_crown.py delete mode 100644 wine_glass.svg diff --git a/FORMATTER_REPLACEMENT_SUMMARY.md b/FORMATTER_REPLACEMENT_SUMMARY.md deleted file mode 100644 index 93a43ba..0000000 --- a/FORMATTER_REPLACEMENT_SUMMARY.md +++ /dev/null @@ -1,300 +0,0 @@ -# Formatter Replacement Summary - -**Date:** 2025-11-18 -**Status:** ✅ Complete - -## Overview - -Successfully replaced all inline formatting functions (65+ occurrences across 12 files) with shared formatter utilities from `$lib/utils/formatters.ts`. - ---- - -## Files Modified - -### Components (3 files) - -1. **DebtBreakdown.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 4 calls to use `formatCurrency(amount, 'CHF', 'de-CH')` - -2. **EnhancedBalance.svelte** - - ✅ Replaced inline `formatCurrency` with utility (kept wrapper for Math.abs) - - ✅ Added import: `import { formatCurrency as formatCurrencyUtil } from '$lib/utils/formatters'` - - ✅ Wrapper function: `formatCurrency(amount) => formatCurrencyUtil(Math.abs(amount), 'CHF', 'de-CH')` - -3. **PaymentModal.svelte** - - ✅ Replaced inline `formatCurrency` with utility (kept wrapper for Math.abs) - - ✅ Added import: `import { formatCurrency as formatCurrencyUtil } from '$lib/utils/formatters'` - - ✅ Wrapper function: `formatCurrency(amount) => formatCurrencyUtil(Math.abs(amount), 'CHF', 'de-CH')` - -### Cospend Pages (5 files) - -4. **routes/cospend/+page.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 5 calls to include CHF and de-CH parameters - -5. **routes/cospend/payments/+page.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 6 calls to include CHF and de-CH parameters - -6. **routes/cospend/payments/view/[id]/+page.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 7 calls to include CHF and de-CH parameters - -7. **routes/cospend/recurring/+page.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 5 calls to include CHF and de-CH parameters - -8. **routes/cospend/settle/+page.svelte** - - ✅ Removed inline `formatCurrency` function - - ✅ Added import: `import { formatCurrency } from '$lib/utils/formatters'` - - ✅ Updated 4 calls to include CHF and de-CH parameters - -### Configuration (1 file) - -9. **svelte.config.js** - - ✅ Added `$utils` alias for `src/utils` directory - - ✅ Enables clean imports: `import { formatCurrency } from '$lib/utils/formatters'` - ---- - -## Changes Summary - -### Before Refactoring - -**Problem:** Duplicate `formatCurrency` functions in 8 files: - -```typescript -// Repeated 8 times across codebase -function formatCurrency(amount) { - return new Intl.NumberFormat('de-CH', { - style: 'currency', - currency: 'CHF' - }).format(amount); -} - -// Usage -{formatCurrency(payment.amount)} -``` - -### After Refactoring - -**Solution:** Single shared utility with consistent usage: - -```typescript -// Once in $lib/utils/formatters.ts -export function formatCurrency( - amount: number, - currency: string = 'EUR', - locale: string = 'de-DE' -): string { - return new Intl.NumberFormat(locale, { - style: 'currency', - currency: currency - }).format(amount); -} - -// Usage in components/pages -import { formatCurrency } from '$lib/utils/formatters'; - -{formatCurrency(payment.amount, 'CHF', 'de-CH')} -``` - ---- - -## Impact - -### Code Duplication Eliminated - -- **Before:** 8 duplicate `formatCurrency` functions -- **After:** 1 shared utility function -- **Reduction:** ~88% less formatting code - -### Function Calls Updated - -- **Total calls updated:** 31 formatCurrency calls -- **Parameters added:** CHF and de-CH to all calls -- **Consistency:** 100% of currency formatting now uses shared utility - -### Lines of Code Removed - -Approximately **40-50 lines** of duplicate code removed across 8 files. - ---- - -## Benefits - -### 1. Maintainability ✅ -- ✅ Single source of truth for currency formatting -- ✅ Future changes only need to update one file -- ✅ Consistent formatting across entire application - -### 2. Consistency ✅ -- ✅ All currency displayed with same format -- ✅ Locale-aware formatting (de-CH) -- ✅ Proper currency symbol placement - -### 3. Testability ✅ -- ✅ Formatting logic has comprehensive unit tests (29 tests) -- ✅ Easy to test edge cases centrally -- ✅ Regression testing in one location - -### 4. Type Safety ✅ -- ✅ TypeScript types for all formatter functions -- ✅ JSDoc comments with examples -- ✅ IDE auto-completion support - -### 5. Extensibility ✅ -- ✅ Easy to add new formatters (date, number, etc.) -- ✅ Support for multiple locales -- ✅ Support for multiple currencies - ---- - -## Remaining Inline Formatting (Optional Future Work) - -### Files Still Using Inline `.toFixed()` - -These files use `.toFixed()` for specific formatting needs. Could be replaced with `formatNumber()` if desired: - -1. **SplitMethodSelector.svelte** - - Uses `.toFixed(2)` for split calculations - - Could use: `formatNumber(amount, 2, 'de-CH')` - -2. **BarChart.svelte** - - Uses `.toFixed(0)` and `.toFixed(2)` for chart labels - - Could use: `formatNumber(amount, decimals, 'de-CH')` - -3. **payments/add/+page.svelte** & **payments/edit/[id]/+page.svelte** - - Uses `.toFixed(2)` and `.toFixed(4)` for currency conversions - - Could use: `formatNumber(amount, decimals, 'de-CH')` - -4. **recurring/edit/[id]/+page.svelte** - - Uses `.toFixed(2)` and `.toFixed(4)` for exchange rates - - Could use: `formatNumber(rate, 4, 'de-CH')` - -5. **IngredientsPage.svelte** - - Uses `.toFixed(3)` for recipe ingredient calculations - - This is domain-specific logic, probably best left as-is - -### Files Using `.toLocaleString()` - -These files use `.toLocaleString()` for date formatting: - -1. **payments/add/+page.svelte** - - Uses `.toLocaleString('de-CH', options)` for next execution date - - Could use: `formatDateTime(date, 'de-CH', options)` - -2. **recurring/edit/[id]/+page.svelte** - - Uses `.toLocaleString('de-CH', options)` for next execution date - - Could use: `formatDateTime(date, 'de-CH', options)` - -**Recommendation:** These are lower priority since they're used less frequently and the pattern is consistent. - ---- - -## Testing Results - -### Unit Tests ✅ - -```bash -Test Files: 2 passed (2) -Tests: 38 passed, 1 skipped (39) -Duration: ~500ms -``` - -**Test Coverage:** -- ✅ formatCurrency function (5 tests) -- ✅ formatDate function (5 tests) -- ✅ formatDateTime function (2 tests) -- ✅ formatNumber function (4 tests) -- ✅ formatRelativeTime function (2 tests) -- ✅ formatFileSize function (6 tests) -- ✅ formatPercentage function (5 tests) -- ✅ Auth middleware (9 tests) - -### Build Status ✅ - -```bash -✓ 149 modules transformed -✔ Build completed successfully -``` - -**No breaking changes:** All existing functionality preserved. - ---- - -## Migration Notes - -### For Future Developers - -**When adding new currency displays:** - -```typescript -// ✅ DO: Use shared formatter -import { formatCurrency } from '$lib/utils/formatters'; -{formatCurrency(amount, 'CHF', 'de-CH')} - -// ❌ DON'T: Create new inline formatters -function formatCurrency(amount) { - return new Intl.NumberFormat('de-CH', { - style: 'currency', - currency: 'CHF' - }).format(amount); -} -``` - -**When adding new number/date formatting:** - -```typescript -// Numbers -import { formatNumber } from '$lib/utils/formatters'; -{formatNumber(value, 2, 'de-CH')} // 2 decimal places - -// Dates -import { formatDate, formatDateTime } from '$lib/utils/formatters'; -{formatDate(date, 'de-CH')} -{formatDateTime(date, 'de-CH', { dateStyle: 'long', timeStyle: 'short' })} -``` - ---- - -## Files Created/Modified - -### Created -- `scripts/replace_formatters.py` - Automated replacement script -- `scripts/update_formatter_calls.py` - Update formatter call parameters -- `scripts/replace-formatters.md` - Progress tracking -- `FORMATTER_REPLACEMENT_SUMMARY.md` - This document - -### Modified -- 8 Svelte components/pages (formatCurrency replaced) -- 1 configuration file (svelte.config.js - added alias) - -### Scripts Used -- Python automation for consistent replacements -- Bash scripts for verification -- Manual cleanup for edge cases - ---- - -## Conclusion - -✅ **Successfully eliminated all duplicate formatCurrency functions** -✅ **31 function calls updated to use shared utility** -✅ **All tests passing (38/38)** -✅ **Build successful with no breaking changes** -✅ **~40-50 lines of duplicate code removed** -✅ **Single source of truth for currency formatting** - -**Result:** Cleaner, more maintainable codebase with consistent formatting across the entire application. Future changes to currency formatting only require updating one file instead of 8. - -**Next Steps (Optional):** -1. Replace remaining `.toFixed()` calls with `formatNumber()` (8 files) -2. Replace `.toLocaleString()` calls with `formatDateTime()` (2 files) -3. Add more formatter utilities as needed (file size, percentages, etc.) diff --git a/TODO_cleanup.md b/TODO_cleanup.md deleted file mode 100644 index eb83d06..0000000 --- a/TODO_cleanup.md +++ /dev/null @@ -1,138 +0,0 @@ -# TypeScript Error Cleanup TODO - -Generated from `pnpm check` output. Total errors found: 1239 - -## Categories - -### 1. Implicit 'any' Types (High Priority - Easy Fixes) -Files with missing type annotations for function parameters - -### 2. Mongoose Type Issues -Property access and type compatibility issues with Mongoose models - -### 3. Null/Undefined Safety -Properties that may be null or undefined - -### 4. Type Mismatches -Arguments and assignments with incompatible types - -### 5. Missing Imports/Definitions -Cannot find name/namespace errors - ---- - -## Detailed Errors - -### Category 1: Implicit 'any' Types - -#### src/lib/components/do_on_key.js -- [x] Line 1:27 - Parameter 'event' implicitly has an 'any' type ✅ -- [x] Line 1:34 - Parameter 'key' implicitly has an 'any' type ✅ -- [x] Line 1:39 - Parameter 'needsctrl' implicitly has an 'any' type ✅ -- [x] Line 1:50 - Parameter 'fn' implicitly has an 'any' type ✅ - -#### src/lib/js/randomize.js -- [x] Line 2:21 - Parameter 'a' implicitly has an 'any' type ✅ -- [x] Line 11:28 - Parameter 'array' implicitly has an 'any' type ✅ - -#### src/utils/cookie.js -- [x] Line 2:35 - Parameter 'request' implicitly has an 'any' type ✅ -- [x] Line 4:45 - Parameter 'cookie' implicitly has an 'any' type ✅ - -#### src/hooks.server.ts -- [ ] Line 26:32 - Binding element 'event' implicitly has an 'any' type -- [ ] Line 26:39 - Binding element 'resolve' implicitly has an 'any' type - -#### src/lib/js/stripHtmlTags.ts -- [x] Line 4:31 - Parameter 'input' implicitly has an 'any' type ✅ - -#### src/lib/utils/settlements.ts -- [ ] Line 51:40 - Parameter 'split' implicitly has an 'any' type -- [ ] Line 57:41 - Parameter 'split' implicitly has an 'any' type - -#### src/routes/[recipeLang=recipeLang]/favorites/+page.server.ts -- [ ] Line 25:49 - Parameter 'recipe' implicitly has an 'any' type - -#### src/routes/api/cospend/payments/+server.ts -- [ ] Line 135:48 - Parameter 'split' implicitly has an 'any' type - -### Category 2: Mongoose/Model Type Issues - -#### src/models/RecurringPayment.ts -- [ ] Line 98:20 - Property 'frequency' does not exist on type - -#### src/routes/api/cospend/debts/+server.ts -- [ ] Line 36:64 - Property '_id' does not exist on FlattenMaps type -- [ ] Line 54:21 - Property '_id' does not exist on FlattenMaps type -- [ ] Line 54:56 - Property '_id' does not exist on FlattenMaps type - -#### src/routes/api/generate-alt-text/+server.ts -- [ ] Line 60:34 - Type 'never[]' is missing properties (DocumentArray) -- [ ] Lines 62-75 - Multiple 'possibly null/undefined' errors for recipe.translations - -#### src/routes/api/generate-alt-text-bulk/+server.ts -- [ ] Lines 93-108 - Similar DocumentArray and null/undefined issues - -### Category 3: Null/Undefined Safety - -#### src/lib/server/middleware/auth.ts -- [ ] Lines 42-44 - Type 'string | null | undefined' not assignable to 'string | undefined' (3 instances) -- [ ] Lines 77-79 - Same issue (3 more instances) - -### Category 4: Error Handling (unknown type) - -#### src/routes/api/cospend/payments/+server.ts -- [ ] Line 91:70 - 'e' is of type 'unknown' - -#### src/routes/api/cospend/payments/[id]/+server.ts -- [ ] Line 26:9 - 'e' is of type 'unknown' -- [ ] Line 88:9 - 'e' is of type 'unknown' -- [ ] Line 121:9 - 'e' is of type 'unknown' - -#### src/routes/api/cospend/upload/+server.ts -- [ ] Line 59:9 - 'err' is of type 'unknown' - -### Category 5: Missing Definitions - -#### src/lib/server/scheduler.ts -- [ ] Line 10:17 - Cannot find namespace 'cron' -- [ ] Line 30:7 - Invalid argument for TaskOptions - -#### src/routes/(main)/settings/+page.server.ts -- [ ] Line 6:22 - Cannot find name 'authenticateUser' - -#### src/hooks.server.ts -- [ ] Lines 39, 51, 61 - error() function doesn't accept custom object format - -### Category 6: Aggregate Pipeline Issues - -#### src/routes/api/cospend/monthly-expenses/+server.ts -- [ ] Line 79:45 - No matching overload for aggregate pipeline -- [ ] Line 115:62 - 'value' is of type 'unknown' -- [ ] Line 125:39 - Type incompatibility in map function - -### Category 7: Svelte Component Props - -#### Various .svelte files -- [ ] Multiple implicit 'any' types in event handlers and derived state -- [ ] Missing prop type definitions -- [ ] Element binding type issues - ---- - -## Quick Wins (Start Here) - -1. **do_on_key.js** - Add type annotations (4 parameters) -2. **randomize.js** - Add type annotations (2 parameters) -3. **cookie.js** - Add type annotations (2 parameters) -4. **stripHtmlTags.ts** - Add input parameter type -5. **Error handling** - Type catch blocks properly (`catch (e: unknown)`) - -## Progress Tracking - -- Total Errors: 1239 -- Fixed: 12 -- Remaining: 1227 -- Categories Completed: Quick Wins (Category 1 - Partial) - -Last Updated: Mon Jan 5 11:48:00 PM CET 2026 diff --git a/dove.svg b/dove.svg deleted file mode 100644 index 2179e7b..0000000 --- a/dove.svg +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - diff --git a/extract_crown.py b/extract_crown.py deleted file mode 100644 index 323d09c..0000000 --- a/extract_crown.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -"""Extract crown emoji from Symbola font as SVG.""" - -import fontforge -import sys - -# Path to Symbola font -font_path = "/usr/share/fonts/TTF/Symbola.ttf" - -# Dove emoji Unicode codepoint -dove_codepoint = 0x1F54A # U+1F54A 🕊️ - -# Output SVG file -output_path = "dove.svg" - -try: - # Open the font - font = fontforge.open(font_path) - - # Select the dove glyph by Unicode codepoint - if dove_codepoint in font: - glyph = font[dove_codepoint] - - # Export as SVG - glyph.export(output_path) - - print(f"✓ Successfully extracted dove emoji to {output_path}") - print(f" Glyph name: {glyph.glyphname}") - print(f" Unicode: U+{dove_codepoint:04X}") - else: - print(f"✗ Dove emoji (U+{dove_codepoint:04X}) not found in font") - sys.exit(1) - - font.close() - -except Exception as e: - print(f"✗ Error: {e}") - sys.exit(1) diff --git a/wine_glass.svg b/wine_glass.svg deleted file mode 100644 index c329266..0000000 --- a/wine_glass.svg +++ /dev/null @@ -1,11 +0,0 @@ - - - - -