refactor: use nullish coalescing and simplify checks in events#709
refactor: use nullish coalescing and simplify checks in events#709kamilwronka wants to merge 1 commit intodevelopfrom
Conversation
Replace || with ?? for nullish coalescing in event-kill and event-wrapped services to prevent incorrect fallback when values are 0 or empty string. Simplify redundant null/undefined checks in event-points where Number.isFinite already handles null and undefined. 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 event service files updated to use nullish-coalescing operators ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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/events/services/event-wrapped.service.ts (1)
701-703: Remove unreachable fallback inmapCountexpression.
countMapStats()already guarantees a numeric result, so the fallback chain after it never executes. Simplifying this improves readability.♻️ Suggested simplification
- const mapCount = - countMapStats(summary.mapStats) ?? heroCoverage?.mapCount ?? 0; + const mapCount = countMapStats(summary.mapStats);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/api/src/events/services/event-wrapped.service.ts` around lines 701 - 703, The assigned mapCount uses an unreachable fallback because countMapStats(summary.mapStats) always returns a number; replace the ternary/fallback chain with a direct assignment. Change the mapCount declaration to call countMapStats(summary.mapStats) only (remove the ?? heroCoverage?.mapCount ?? 0 parts) so the code reads: const mapCount = countMapStats(summary.mapStats); and remove any now-unnecessary references to heroCoverage?.mapCount in that expression.
🤖 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/events/services/event-wrapped.service.ts`:
- Around line 701-703: The assigned mapCount uses an unreachable fallback
because countMapStats(summary.mapStats) always returns a number; replace the
ternary/fallback chain with a direct assignment. Change the mapCount declaration
to call countMapStats(summary.mapStats) only (remove the ??
heroCoverage?.mapCount ?? 0 parts) so the code reads: const mapCount =
countMapStats(summary.mapStats); and remove any now-unnecessary references to
heroCoverage?.mapCount in that expression.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a6095f9a-41cf-479c-a5d5-70375eddabd5
📒 Files selected for processing (3)
apps/api/src/events/services/event-kill.service.tsapps/api/src/events/services/event-points.service.tsapps/api/src/events/services/event-wrapped.service.ts
Summary
||with??for nullish coalescing inevent-kill.service.tsandevent-wrapped.service.ts— prevents incorrect fallback when values are0or empty string=== null || === undefinedchecks inevent-points.service.ts—Number.isFinite()already returnsfalsefornullandundefinedWhy each change is safe
||→??:Map.get()and optional chaining returnundefined(not other falsy values) on miss, so??is semantically correct. The key fix iscountMapStats()inevent-wrapped.service.ts— it can return0(valid), which||would incorrectly treat as falsy.Number.isFiniteguards:Number.isFinite(null)andNumber.isFinite(undefined)both returnfalse, making the explicit null/undefined checks redundant.Files touched
apps/api/src/events/services/event-kill.service.ts— 6||→??replacementsapps/api/src/events/services/event-points.service.ts— 2 simplified conditionsapps/api/src/events/services/event-wrapped.service.ts— 1||→??replacementResidual risks
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit