From 4eb51819adf67c5192d93f702f3adf292f051495 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:21:38 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20[code=20health]=20Refactor=20mag?= =?UTF-8?q?ic=20numbers=20in=20yearInReviewUtils.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 **What:** Replaced hardcoded values `7` and `24` with descriptive constants `DAYS_IN_WEEK` and `HOURS_IN_DAY` in `src/lib/yearInReviewUtils.ts`. 💡 **Why:** Using descriptive constants improves the maintainability and readability of the codebase by clarifying the meaning of previously 'magic numbers'. ✅ **Verification:** Confirmed that the code formats correctly, lint checks pass, all tests pass, and the application builds successfully. No functional changes were made. ✨ **Result:** Improved maintainability, code readability, and code quality. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/yearInReviewUtils.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/yearInReviewUtils.ts b/src/lib/yearInReviewUtils.ts index 52cee3ea..66e1f982 100644 --- a/src/lib/yearInReviewUtils.ts +++ b/src/lib/yearInReviewUtils.ts @@ -1,3 +1,6 @@ +const DAYS_IN_WEEK = 7; +const HOURS_IN_DAY = 24; + /** * Builds a 7x24 hourly heatmap (7 days x 24 hours) from an array of commit date strings. * @@ -5,7 +8,7 @@ * @returns A 2D array representing the heatmap [day][hour]. */ export function buildHourlyHeatmapFromCommitDates(commitDates: string[]): number[][] { - const heatmap = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + const heatmap = Array.from({ length: DAYS_IN_WEEK }, () => Array.from({ length: HOURS_IN_DAY }, () => 0)); // Performance Optimization: Cache weekday calculations to avoid expensive Date parsing in the loop const dayCache = new Map(); @@ -71,17 +74,17 @@ function parseFallbackDate(dateString: string, heatmap: number[][]): void { export function getMostActiveHour(heatmap: number[][]): number { const isValidHeatmap = Array.isArray(heatmap) && - heatmap.length === 7 && - heatmap.every((row) => Array.isArray(row) && row.length === 24 && row.every((count) => Number.isFinite(count))); + heatmap.length === DAYS_IN_WEEK && + heatmap.every((row) => Array.isArray(row) && row.length === HOURS_IN_DAY && row.every((count) => Number.isFinite(count))); if (!isValidHeatmap) { return 0; } let maxCount = -1; let mostActiveHour = 0; - for (let hour = 0; hour < 24; hour += 1) { + for (let hour = 0; hour < HOURS_IN_DAY; hour += 1) { let total = 0; - for (let day = 0; day < 7; day += 1) { + for (let day = 0; day < DAYS_IN_WEEK; day += 1) { total += heatmap[day][hour]; } if (total > maxCount) { @@ -100,7 +103,7 @@ export function getMostActiveHour(heatmap: number[][]): number { */ export function getMostActiveDayFromCalendar(calendar: { date: string; count: number }[]): string { const weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - const totals = Array.from({ length: 7 }, () => 0); + const totals = Array.from({ length: DAYS_IN_WEEK }, () => 0); for (const day of calendar) { if (day.count <= 0) {