refactor: small type safety and readability cleanups#699
refactor: small type safety and readability cleanups#699kamilwronka wants to merge 1 commit intodevelopfrom
Conversation
- Type FINAL_JOB_STATUSES as DbNotificationJobStatus[] to eliminate 4 redundant type assertions - Cache Object.keys(mappedLootShare).length in a local variable instead of computing it 3 times - Extract inline NPC type array to named DEFAULT_BOSS_NPC_TYPES constant Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThree refactoring changes optimize code clarity and performance: extracting a module-level constant for reusable NPC types, precomputing a value to eliminate repeated calculations, and simplifying type declarations by removing redundant type assertions throughout conditional checks and database queries. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/api/src/kills/kills.controller.ts (1)
31-37: Move the constant declaration after all imports.The constant
DEFAULT_BOSS_NPC_TYPESis declared between two import blocks (lines 31-36 are between the decorator imports ending at line 30 and the service imports starting at line 37). This breaks the conventional module structure where all imports should be grouped at the top, followed by constants and declarations.♻️ Suggested reordering
Move lines 32-36 after line 56 (after all imports):
import { GuildData } from "src/shared/decorators/guild-data.decorator"; + +const DEFAULT_BOSS_NPC_TYPES: NpcType[] = [ + NpcType.TITAN, + NpcType.HERO, + NpcType.EVENT_HERO, +]; `@ApiTags`("kills")And remove the constant from its current location between imports.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/api/src/kills/kills.controller.ts` around lines 31 - 37, The constant DEFAULT_BOSS_NPC_TYPES (using NpcType.TITAN, NpcType.HERO, NpcType.EVENT_HERO) is declared between import blocks; move its declaration so all imports remain grouped at the top of the module. Remove the current inline declaration and re-add the DEFAULT_BOSS_NPC_TYPES constant immediately after the final import (after the block that brings in KillsService and other locals) so imports appear first and constants/declarations follow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/api/src/kills/kills.controller.ts`:
- Around line 31-37: The constant DEFAULT_BOSS_NPC_TYPES (using NpcType.TITAN,
NpcType.HERO, NpcType.EVENT_HERO) is declared between import blocks; move its
declaration so all imports remain grouped at the top of the module. Remove the
current inline declaration and re-add the DEFAULT_BOSS_NPC_TYPES constant
immediately after the final import (after the block that brings in KillsService
and other locals) so imports appear first and constants/declarations follow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dc7be552-d2a9-4a00-b368-532d6515602e
📒 Files selected for processing (3)
apps/api/src/kills/kills.controller.tsapps/api/src/loots/loots.service.tsapps/api/src/notifications/notification-job.service.ts
Summary
FINAL_JOB_STATUSESasDbNotificationJobStatus[]instead ofas const, eliminating 4 redundant type assertions (as unknown asandas readonly) at usage sitesObject.keys(mappedLootShare).lengthin amappedItemsCountvariable instead of computing it 3 times in succession[NpcType.TITAN, NpcType.HERO, NpcType.EVENT_HERO]array to a namedDEFAULT_BOSS_NPC_TYPESconstant for readabilitySafety
All changes are behavior-preserving:
FINAL_JOB_STATUSESchange only widens the type from a narrow readonly tuple toDbNotificationJobStatus[], which is what every usage site was already casting tomappedItemsCountvariable caches an already-computed value with no side effectsDEFAULT_BOSS_NPC_TYPESconstant is a direct extraction of an inline literalTest plan
pnpm lintpasses (0 errors, 2 pre-existing warnings)pnpm format:checkpasses on changed filespnpm test— all 131 running tests pass; 32 pre-existing failures due to unrelated@lootlog/nest-sharedpackage resolution issue🤖 Generated with Claude Code
Summary by CodeRabbit