this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix ESLint issues in web server and API

- Remove unnecessary async from synchronous functions
- Use nullish coalescing for defaults
- Add explicit type annotations
- Fix strict boolean expressions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

alice 5c32c88c f5ee12a3

+47 -35
+42 -30
src/web/api.ts
··· 4 4 5 5 type ApiHandler = (req: Request, url: URL) => Promise<Response>; 6 6 7 + interface URLWithParams extends URL { 8 + params?: Record<string, string>; 9 + } 10 + 7 11 const routes: Record<string, ApiHandler> = { 8 12 'GET /api/days': handleGetDays, 9 13 'GET /api/days/:date': handleGetDayDetail, ··· 30 34 if (params !== null) { 31 35 try { 32 36 // Attach params to URL for handler access 33 - (url as any).params = params; 37 + (url as URLWithParams).params = params; 34 38 return await handler(req, url); 35 39 } catch (error) { 36 40 console.error('API error:', error); ··· 53 57 54 58 const params: Record<string, string> = {}; 55 59 56 - for (let i = 0; i < patternParts.length; i++) { 57 - const patternPart = patternParts[i]; 58 - const pathPart = pathParts[i]; 60 + for (const [i, patternPart] of patternParts.entries()) { 61 + // pathPart is guaranteed to exist since we verified lengths match 62 + const pathPart = pathParts[i] ?? ''; 59 63 60 64 if (patternPart.startsWith(':')) { 61 65 params[patternPart.slice(1)] = pathPart; ··· 79 83 80 84 // Handlers 81 85 82 - async function handleGetDays(req: Request, url: URL): Promise<Response> { 86 + function handleGetDays(_req: Request, url: URL): Promise<Response> { 83 87 const limitParam = url.searchParams.get('limit'); 84 - const days = limitParam ? getDays(parseInt(limitParam)) : getDays(); 85 - return jsonResponse(days); 88 + const days = limitParam !== null ? getDays(parseInt(limitParam, 10)) : getDays(); 89 + return Promise.resolve(jsonResponse(days)); 86 90 } 87 91 88 - async function handleGetDayDetail(req: Request, url: URL): Promise<Response> { 89 - const params = (url as any).params as Record<string, string>; 90 - const date = params.date; 92 + function handleGetDayDetail(_req: Request, url: URL): Promise<Response> { 93 + const params = (url as { params?: Record<string, string> }).params; 94 + const date = params?.date; 95 + 96 + if (date === undefined) { 97 + return Promise.resolve(jsonResponse({ error: 'Missing date parameter' }, 400)); 98 + } 91 99 92 100 const detail = getDayDetail(date); 93 - if (!detail) { 94 - return jsonResponse({ error: 'Day not found' }, 404); 101 + if (detail === null) { 102 + return Promise.resolve(jsonResponse({ error: 'Day not found' }, 404)); 95 103 } 96 104 97 - return jsonResponse(detail); 105 + return Promise.resolve(jsonResponse(detail)); 98 106 } 99 107 100 - async function handleGetDayBrag(req: Request, url: URL): Promise<Response> { 101 - const params = (url as any).params as Record<string, string>; 102 - const date = params.date; 108 + function handleGetDayBrag(_req: Request, url: URL): Promise<Response> { 109 + const params = (url as { params?: Record<string, string> }).params; 110 + const date = params?.date; 111 + 112 + if (date === undefined) { 113 + return Promise.resolve(jsonResponse({ error: 'Missing date parameter' }, 400)); 114 + } 103 115 104 116 const detail = getDayDetail(date); 105 - if (!detail) { 106 - return jsonResponse({ error: 'Day not found' }, 404); 117 + if (detail === null) { 118 + return Promise.resolve(jsonResponse({ error: 'Day not found' }, 404)); 107 119 } 108 120 109 - return jsonResponse({ 121 + return Promise.resolve(jsonResponse({ 110 122 date, 111 - bragSummary: detail.bragSummary || 'No summary available', 123 + bragSummary: detail.bragSummary ?? 'No summary available', 112 124 projectCount: detail.projects.length, 113 125 sessionCount: detail.stats.totalSessions, 114 - }); 126 + })); 115 127 } 116 128 117 - async function handleGetStats(req: Request, url: URL): Promise<Response> { 129 + function handleGetStats(_req: Request, _url: URL): Promise<Response> { 118 130 const stats = getStats(); 119 - return jsonResponse(stats); 131 + return Promise.resolve(jsonResponse(stats)); 120 132 } 121 133 122 - async function handleRefresh(req: Request, url: URL): Promise<Response> { 134 + async function handleRefresh(_req: Request, _url: URL): Promise<Response> { 123 135 // Run processing in background 124 136 const startTime = Date.now(); 125 137 ··· 146 158 } 147 159 } 148 160 149 - async function handleGetProjects(req: Request, url: URL): Promise<Response> { 161 + function handleGetProjects(_req: Request, url: URL): Promise<Response> { 150 162 const status = url.searchParams.get('status') as ProjectStatus | null; 151 - const projects = getProjects(status || undefined); 152 - return jsonResponse(projects); 163 + const projects = getProjects(status ?? undefined); 164 + return Promise.resolve(jsonResponse(projects)); 153 165 } 154 166 155 - async function handleUpdateProjectStatus(req: Request, url: URL): Promise<Response> { 156 - const body = await req.json() as { path: string; status: ProjectStatus }; 167 + async function handleUpdateProjectStatus(req: Request, _url: URL): Promise<Response> { 168 + const body = (await req.json()) as { path?: string; status?: ProjectStatus }; 157 169 158 - if (!body.path || !body.status) { 170 + if (body.path === undefined || body.status === undefined) { 159 171 return jsonResponse({ error: 'Missing path or status' }, 400); 160 172 } 161 173
+5 -5
src/web/server.ts
··· 3 3 import { existsSync } from 'fs'; 4 4 import { handleApiRequest } from './api'; 5 5 6 - const PORT = parseInt(process.env.PORT || '3456'); 6 + const PORT = parseInt(process.env.PORT ?? '3456'); 7 7 const STATIC_DIR = join(import.meta.dir, '../../dist'); 8 8 9 - export async function startServer() { 10 - console.log(`\n🚀 Starting worklog server on http://localhost:${PORT}\n`); 9 + export function startServer() { 10 + console.log(`\n🚀 Starting worklog server on http://localhost:${String(PORT)}\n`); 11 11 12 12 serve({ 13 13 port: PORT, ··· 31 31 console.log('Server running. Press Ctrl+C to stop.\n'); 32 32 } 33 33 34 - async function serveStatic(pathname: string): Promise<Response> { 34 + function serveStatic(pathname: string): Response { 35 35 // Map pathname to file 36 36 let filePath = pathname === '/' ? '/index.html' : pathname; 37 37 filePath = join(STATIC_DIR, filePath); ··· 100 100 woff: 'font/woff', 101 101 woff2: 'font/woff2', 102 102 }; 103 - return types[ext || ''] || 'application/octet-stream'; 103 + return types[ext ?? ''] ?? 'application/octet-stream'; 104 104 }