Skip to content

No unused vars#844

Merged
CodeWithCJ merged 5 commits intoCodeWithCJ:mainfrom
Sim-sat:no-unused-vars
Mar 5, 2026
Merged

No unused vars#844
CodeWithCJ merged 5 commits intoCodeWithCJ:mainfrom
Sim-sat:no-unused-vars

Conversation

@Sim-sat
Copy link
Contributor

@Sim-sat Sim-sat commented Mar 5, 2026

Description

Fixes 4 typescript rules in preparation of strict typescript:

  • strictFunctionTypes
  • no unusedLocals and parameters
  • no implicit any

Also adds (but no fixes required):

  • alwaysStrict
  • noImplicitThis
  • strictBindCallApply
  • useUnknownInCatchVariables,

I also realized the mini nutrion data doesn't update when adding a food so I added the required invalidation.

Edit:

I just saw #842 and decided to add it here since it's just one line.

Related Issue

PR type [ ] Issue [x] New Feature [ ] Documentation
Linked Issue: #842

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the frontend's code quality and maintainability by enabling and addressing issues arising from strict TypeScript compiler options. The changes ensure better type safety, eliminate unused code, and standardize error handling. A key functional improvement is the refactoring of food entry cache invalidation, which resolves a bug where nutrition data was not updating correctly, leading to a more reliable user experience.

Highlights

  • Strict TypeScript Enforcement: Enabled several strict TypeScript compiler options in tsconfig.app.json, including noUnusedLocals, noUnusedParameters, noImplicitAny, alwaysStrict, noImplicitThis, strictBindCallApply, useUnknownInCatchVariables, and strictFunctionTypes. This significantly enhances type safety and code quality across the frontend.
  • Centralized Food Entry Cache Invalidation: Introduced a new useFoodEntryInvalidation hook to centralize and streamline the cache invalidation logic for all food-related mutations (create, update, delete, copy, meal operations). This resolves an issue where mini nutrition data was not consistently updating after food entry modifications.
  • Type Safety and Unused Code Cleanup: Performed extensive refactoring across numerous files to comply with the newly enforced strict TypeScript rules. This involved adding explicit type annotations, updating function signatures, removing unused variables and imports, and refining error handling with the getErrorMessage utility.
  • API Service Updates: Modified userManagementService.getUserProfile to no longer require a userId parameter, implying it now fetches the profile of the currently authenticated user. The authType parameter was also removed from setActiveUser calls in authentication flows.
Changelog
  • SparkyFitnessFrontend/package.json
    • Added @types/papaparse dependency.
  • SparkyFitnessFrontend/pnpm-lock.yaml
    • Updated lockfile to include @types/papaparse.
  • SparkyFitnessFrontend/src/App.tsx
    • Replaced null with React fragment <></> in ComponentFallback.
  • SparkyFitnessFrontend/src/api/Admin/userManagementService.ts
    • Removed userId parameter from getUserProfile function signature and call.
  • SparkyFitnessFrontend/src/api/Auth/auth.ts
    • Added AccessibleUser type annotation to map function parameter.
  • SparkyFitnessFrontend/src/api/Chatbot/Chatbot_ExerciseHandler.ts
    • Removed unused exerciseEntry variable.
  • SparkyFitnessFrontend/src/api/Chatbot/Chatbot_MeasurementHandler.ts
    • Added index signature to CheckInPayload interface.
    • Updated upsertError type to unknown and used getErrorMessage for consistent error handling.
  • SparkyFitnessFrontend/src/api/Exercises/exerciseEntryService.ts
    • Refactored iteration over object keys to use Object.entries for better type inference.
    • Ensured values appended to FormData are explicitly converted to String.
  • SparkyFitnessFrontend/src/api/Foods/nutrionix.ts
    • Imported getErrorMessage utility.
    • Defined NutritionixMappedItem interface for better type clarity.
    • Applied NutritionixMappedItem type to mapped food items.
    • Used getErrorMessage in fetchFoodDataProvider catch block.
  • SparkyFitnessFrontend/src/api/Goals/goals.ts
    • Removed unused rest variable from object destructuring.
  • SparkyFitnessFrontend/src/components/AppSetup.tsx
    • Added null return type annotation to AppSetup component.
  • SparkyFitnessFrontend/src/components/FoodSearch/BarcodeScanner.tsx
    • Added explicit type annotations for scanAreaSize and internalContinuousMode state variables.
    • Updated handleManualBarcodeSubmit event type to React.SubmitEvent.
  • SparkyFitnessFrontend/src/components/FoodSearch/FoodResultCard.tsx
    • Imported EnergyUnit type.
    • Updated NutrientGridConfig interface to use EnergyUnit for energy unit types.
  • SparkyFitnessFrontend/src/components/FoodSearch/FoodSearch.tsx
    • Made id property optional in NutritionixItem interface.
    • Added Food type annotation to map function parameters for recent and top foods.
  • SparkyFitnessFrontend/src/components/FoodSearch/NutrientGrid.tsx
    • Imported EnergyUnit type.
    • Defined and applied NutrientGridProps interface to the component.
  • SparkyFitnessFrontend/src/components/FoodUnitSelector.tsx
    • Updated handleSubmit event type to React.SubmitEvent<HTMLFormElement>.
    • Added HTMLInputElement type annotation to focusAndSelect callback parameter.
  • SparkyFitnessFrontend/src/components/GitHubStarCounter.tsx
    • Removed unused CACHE_KEY_PREFIX constant.
  • SparkyFitnessFrontend/src/components/GlobalNotificationIcon.tsx
    • Added null return type annotation to GlobalNotificationIcon component.
    • Added debugging console.log and setIsDialogOpen(false) within an if block.
  • SparkyFitnessFrontend/src/components/LanguageHandler.tsx
    • Added null return type annotation to LanguageHandler component.
  • SparkyFitnessFrontend/src/components/MealBuilder.tsx
    • Removed unused Meal type import.
    • Removed unused resultMeal variable in handleSaveMeal.
  • SparkyFitnessFrontend/src/components/OidcCallback.tsx
    • Removed authType parameter from setActiveUser call.
  • SparkyFitnessFrontend/src/components/Onboarding/DietApproach.tsx
    • Updated setLocalSelectedDiet prop type to a simpler function signature.
  • SparkyFitnessFrontend/src/hooks/CheckIn/useCheckInLogic.ts
    • Removed currentUserId parameter from userManagementService.getUserProfile() call.
  • SparkyFitnessFrontend/src/hooks/Diary/useDailyProgress.ts
    • Removed user!.id parameter from userManagementService.getUserProfile() call.
  • SparkyFitnessFrontend/src/hooks/Diary/useFoodEntries.ts
    • Imported diaryReportKeys and useFoodEntryInvalidation.
    • Refactored onSuccess callbacks for all food entry mutations to use useFoodEntryInvalidation.
  • SparkyFitnessFrontend/src/hooks/Foods/useFoods.ts
    • Removed return keyword from queryClient.invalidateQueries calls.
  • SparkyFitnessFrontend/src/hooks/Reports/useReports.ts
    • Imported MeasurementUnit and WeightUnit types.
    • Updated converters interface in useReportsData to use MeasurementUnit and WeightUnit.
  • SparkyFitnessFrontend/src/hooks/useAuth.tsx
    • Removed authType parameter from AuthContextType and setActiveUser function signature.
  • SparkyFitnessFrontend/src/hooks/useGeneralQueries.ts
    • Added default enabled = true to useLatestReleaseQuery options and explicitly passed enabled to useQuery.
  • SparkyFitnessFrontend/src/hooks/useInvalidateKeys.ts
    • Imported diaryReportKeys, foodEntryKeys, foodEntryMealKeys.
    • Created useFoodEntryInvalidation hook to centralize food entry related query invalidation.
  • SparkyFitnessFrontend/src/lib/auth-client.ts
    • Reordered imports for better-auth/client/plugins.
    • Added as unknown as BetterAuthClientPlugin type assertion for adminClient() plugin.
  • SparkyFitnessFrontend/src/lib/scannerEngines/ZxingEngine.ts
    • Renamed unused constraints parameter to _constraints.
  • SparkyFitnessFrontend/src/pages/Admin/UserManagement.tsx
    • Updated col type from string to keyof User in SortableHeadProps.
  • SparkyFitnessFrontend/src/pages/Auth/Auth.tsx
    • Removed authType parameter from setActiveUser calls.
  • SparkyFitnessFrontend/src/pages/Auth/MfaChallenge.tsx
    • Removed authType parameter from setActiveUser calls.
  • SparkyFitnessFrontend/src/pages/CheckIn/RecentActivity.tsx
    • Imported MeasurementUnit and WeightUnit types.
    • Updated convertMeasurement and convertWeight prop types to use MeasurementUnit and WeightUnit.
  • SparkyFitnessFrontend/src/pages/CheckIn/SleepEntrySection.tsx
    • Removed unused sonnerToast import.
    • Removed unused handleSaveNewSessionStageEvents and handleDiscardNewSessionStageEvents functions.
  • SparkyFitnessFrontend/src/pages/Diary/ExercisePresetEntryDisplay.tsx
    • Removed unused usePreferences import and loggingLevel variable.
  • SparkyFitnessFrontend/src/pages/Errors/ChartErrorFallback.tsx
    • Imported type FallbackProps and getErrorMessage.
    • Used getErrorMessage(error) instead of error.message for displaying error messages.
  • SparkyFitnessFrontend/src/pages/Exercises/AddExerciseDialog.tsx
    • Defined ImportConflictError interface for specific error handling.
    • Applied ImportConflictError type assertion in the catch block.
  • SparkyFitnessFrontend/src/pages/Exercises/WorkoutPresetsManager.tsx
    • Updated newPresetData type to exclude user_id from the Omit utility type.
  • SparkyFitnessFrontend/src/pages/Fasting/FastingTimerRing.tsx
    • Removed showZone prop from FastingTimerRingProps and its usage.
  • SparkyFitnessFrontend/src/pages/Fasting/FastingZoneBar.tsx
    • Removed unused isFuture variable.
  • SparkyFitnessFrontend/src/pages/Foods/FoodImportFromCSV.tsx
    • Imported FoodDataForBackend type.
    • Updated onSave prop type to use FoodDataForBackend[].
    • Changed generateUniqueId to use slice instead of substr.
    • Added index signature to CSVData interface.
    • Updated handleSubmit event type to React.SubmitEvent.
  • SparkyFitnessFrontend/src/pages/Foods/MealUnitSelector.tsx
    • Updated handleSubmit event type to React.SubmitEvent<HTMLFormElement>.
    • Added HTMLInputElement type annotation to focusAndSelect callback parameter.
  • SparkyFitnessFrontend/src/pages/Reports/ActivityReportVisualizer.tsx
    • Added type assertions for rawMetricDescriptors and rawHrZones.
  • SparkyFitnessFrontend/src/pages/Reports/MuscleGroupRecoveryTracker.tsx
    • Removed unused type React import.
  • SparkyFitnessFrontend/src/pages/Reports/NutritionChartsGrid.tsx
    • Removed useState import and isMounted state, simplifying component rendering logic.
  • SparkyFitnessFrontend/src/pages/Reports/ReportsTables.tsx
    • Imported DailyExerciseEntry from types/reports.
    • Updated prData type from unknown to PersonalRecordsMap.
    • Removed unused entryDate variable.
  • SparkyFitnessFrontend/src/pages/Reports/SleepScience/EnergySchedule.tsx
    • Imported ReactNode type.
    • Updated labelFormatter type to handle ReactNode.
  • SparkyFitnessFrontend/src/pages/Reports/SleepStageChart.tsx
    • Removed unused zoomLevel parameter from the ZoomableChart render prop.
  • SparkyFitnessFrontend/src/pages/Reports/SleepSummaryCard.tsx
    • Removed unused type React import.
  • SparkyFitnessFrontend/src/pages/Settings/CalculationSettings.tsx
    • Removed several set...Context functions from usePreferences destructuring.
  • SparkyFitnessFrontend/src/tests/components/AIServiceSettings.test.tsx
    • Removed commented-out lines related to finding service cards.
  • SparkyFitnessFrontend/src/tests/setupTests.ts
    • Added as unknown type assertion for onchange property in matchMedia mock.
  • SparkyFitnessFrontend/src/tests/test-utils.tsx
    • Renamed unused e parameter to _e in QueryCache's onError callback.
  • SparkyFitnessFrontend/src/types/auth.ts
    • Added optional access control properties (can_manage_diary, can_manage_checkin, can_view_reports, can_view_food_library) to AccessibleUser interface.
  • SparkyFitnessFrontend/src/types/reports.ts
    • Added index signature to DailyExerciseEntry interface.
  • SparkyFitnessFrontend/src/utils/calorieCalculations.ts
    • Removed adaptiveTdee parameter from computeCaloriesRemaining function.
  • SparkyFitnessFrontend/src/utils/chartUtils.ts
    • Removed minRangeThreshold from calculateSmartYAxisDomain options.
    • Added as unknown type assertion for forceMin in getChartConfig.
  • SparkyFitnessFrontend/src/utils/foodSearch.ts
    • Removed unused GlycemicIndex import and FatSecretNutrientData interface.
  • SparkyFitnessFrontend/src/utils/nutritionCalculations.ts
    • Added type assertions (typedAcc, accRecord) for accumulator objects in calculateDayTotals and getMealTotals.
  • SparkyFitnessFrontend/src/utils/reportUtil.ts
    • Imported MeasurementUnit and WeightUnit types.
    • Updated type definitions for exportBodyMeasurements and formatCustomChartData to use MeasurementUnit and WeightUnit.
    • Added type assertions for customNutrientsSource and totals in exportFoodDiary.
  • SparkyFitnessFrontend/ts.txt
    • Added new empty file.
  • SparkyFitnessFrontend/tsconfig.app.json
    • Enabled strict TypeScript compiler options: noUnusedLocals, noUnusedParameters, noImplicitAny, noFallthroughCasesInSwitch, alwaysStrict, noImplicitThis, strictBindCallApply, useUnknownInCatchVariables, strictFunctionTypes.
Activity
  • The pull request author, Sim-sat, initiated this PR to address several TypeScript strictness rules and a specific bug related to nutrition data updates.
  • The author explicitly mentioned running pnpm run validate, indicating adherence to quality checks for frontend changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great step towards improving the codebase's type safety by enabling several strict TypeScript rules. The changes consistently address issues like unused variables, implicit any types, and improve function signatures. The refactoring of query invalidations into a custom useFoodEntryInvalidation hook is a particularly nice improvement for maintainability, and it also fixes a bug where nutrition data wasn't updating.

I've found one minor issue related to what appears to be leftover debugging code. My feedback is included in the comments below.

Note: Security Review did not run due to the size of the PR.

Comment on lines +19 to +22
if (isDialogOpen) {
console.log(reviewItems);
setIsDialogOpen(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if block appears to be dead code. The isDialogOpen state is initialized to false and is never updated to true, so this condition will never be met. Additionally, it contains a console.log, which should generally be avoided in production code. It seems like this might be leftover debugging code and can be safely removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GlobalNotificationIcon is not yet implemented. This code only removes typescript errors from it

@CodeWithCJ CodeWithCJ merged commit 33cadea into CodeWithCJ:main Mar 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants