Refactor: Address ESLint warnings and tighten TypeScript types#62
Refactor: Address ESLint warnings and tighten TypeScript types#62APPLEPIE6969 wants to merge 1 commit intomainfrom
Conversation
- Remove unused variables and imports across components and library files - Upgrade `@ts-ignore` to `@ts-expect-error` with descriptive comments - Replace generic `any` types with `unknown` where applicable - Restore `any` for `parseJSONFromAI` to prevent breaking dot-chaining - Fix unescaped HTML quotes in JSX Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis pull request applies systematic type safety improvements and error handling modernization across the codebase. Changes include replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
components/VoiceInput.tsx (1)
120-134: Consider defensiveinstanceofcheck before accessing Error properties.The cast
err as Errorassumes the thrown value is always an Error object. WhilegetUserMediatypically throwsDOMException, any thrown value could potentially reach this catch. If a non-Error is thrown,error.nameanderror.messagewould beundefined, resulting in a degraded error message.🛡️ Suggested defensive error handling
- } catch (err: unknown) { - const error = err as Error; - console.error("Mic Access Error:", error.name, error.message) + } catch (err: unknown) { + const error = err instanceof Error ? err : new Error(String(err)); + const errorName = err instanceof Error ? err.name : 'UnknownError'; + console.error("Mic Access Error:", errorName, error.message) setIsProcessing(false) - setLastError(error.name) + setLastError(errorName) - if (error.name === 'NotAllowedError' || error.name === 'PermissionDeniedError' || error.name === 'NotSecureContext') { + if (errorName === 'NotAllowedError' || errorName === 'PermissionDeniedError' || errorName === 'NotSecureContext') { setShowPermissionPrompt(true) - } else if (error.name === 'NotFoundError' || error.name === 'DevicesNotFoundError') { + } else if (errorName === 'NotFoundError' || errorName === 'DevicesNotFoundError') { alert("No microphone found. Please connect a microphone and try again.") - } else if (error.name === 'NotReadableError' || error.name === 'TrackStartError') { + } else if (errorName === 'NotReadableError' || errorName === 'TrackStartError') { alert("Your microphone is currently being used by another application.") } else { - alert(`Microphone error (${error.name}): ${error.message}`) + alert(`Microphone error (${errorName}): ${error.message}`) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/VoiceInput.tsx` around lines 120 - 134, The catch block in start/handle voice acquisition assumes err is an Error; change it to defensively detect and normalize the thrown value before accessing properties: inside the catch for getUserMedia, replace the naive cast (err as Error) with a guard that checks instanceof Error (or DOMException) and otherwise builds a fallback error object (e.g., { name: String(err?.name ?? err) || 'UnknownError', message: String(err?.message ?? err) || '' }), then use that normalized object when calling console.error, setIsProcessing, setLastError, setShowPermissionPrompt and when evaluating error.name cases (keep existing names like 'NotAllowedError', 'NotFoundError', 'NotReadableError' and fallback branch) so non-Error throws won’t produce undefined properties.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@components/VoiceInput.tsx`:
- Around line 120-134: The catch block in start/handle voice acquisition assumes
err is an Error; change it to defensively detect and normalize the thrown value
before accessing properties: inside the catch for getUserMedia, replace the
naive cast (err as Error) with a guard that checks instanceof Error (or
DOMException) and otherwise builds a fallback error object (e.g., { name:
String(err?.name ?? err) || 'UnknownError', message: String(err?.message ?? err)
|| '' }), then use that normalized object when calling console.error,
setIsProcessing, setLastError, setShowPermissionPrompt and when evaluating
error.name cases (keep existing names like 'NotAllowedError', 'NotFoundError',
'NotReadableError' and fallback branch) so non-Error throws won’t produce
undefined properties.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a2228e1e-19b7-479c-af13-9622dfae0533
📒 Files selected for processing (14)
app/api/tutor/live/route.tsapp/create/page.tsxcomponents/DailyInsight.tsxcomponents/TutorialOverlay.tsxcomponents/VoiceInput.tsxlib/ai-utils.tslib/auth.tslib/i18n-utils.tslib/i18n.tsxlib/ratelimit.test.tslib/security.test.tslib/security.tslib/setupTests.tsmiddleware.ts
This PR performs a proactive code cleanup to address technical debt and improve code quality based on ESLint output:
components/VoiceInput.tsx,components/DailyInsight.tsx,middleware.ts, etc.anywithunknowninlib/security.tsandlib/i18n-utils.tsto improve type safety, while explicitly allowinganywith an eslint-disable forparseJSONFromAIto maintain compatibility with downstream JSON consumers.@ts-ignorecomments inlib/auth.ts,lib/security.test.ts, andlib/setupTests.tsto@ts-expect-errorwith required descriptive reasons.components/DailyInsight.tsx.No business logic was altered; these changes purely address static analysis warnings.
PR created automatically by Jules for task 3532913260198697731 started by @APPLEPIE6969
Summary by CodeRabbit
Bug Fixes
Refactor