Skip to content

refactor: replace || with ?? for nullish coalescing#707

Open
kamilwronka wants to merge 1 commit intodevelopfrom
refactor/small-cleanup-20260408
Open

refactor: replace || with ?? for nullish coalescing#707
kamilwronka wants to merge 1 commit intodevelopfrom
refactor/small-cleanup-20260408

Conversation

@kamilwronka
Copy link
Copy Markdown
Contributor

@kamilwronka kamilwronka commented Apr 8, 2026

Summary

  • migrate-loots.ts: Removed redundant ?? undefined in getItemTypeByCl (return type already allows undefined)
  • migrate-loots.ts: Changed player.hpp || null to player.hpp ?? null to preserve 0 as a valid HP value
  • event-kill.service.ts: Changed || 0, || "", || null to ?? 0, ?? "", ?? null for numeric/nullable fields in map data builders (3 locations)

Why this is safe

All changes only affect behavior when values are falsy-but-valid (0, "", false). For Map.get() calls the behavior is identical since missing keys return undefined. For numeric fields like presenceTimeSeconds, afkTimeSeconds, and hpp, ?? correctly preserves 0 instead of falling through to the default.

Test plan

  • All 52 test suites pass (599 tests)
  • Lint passes (pre-existing warnings only)
  • Format check passes on changed files
  • Pre-commit hooks pass

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Improved data accuracy for player statistics and event records by fixing serialization logic to correctly preserve zero values and empty strings instead of incorrectly converting them to null.

…ant ?? undefined

- migrate-loots.ts: remove redundant `?? undefined` in getItemTypeByCl
- migrate-loots.ts: use ?? instead of || for hpp (preserves 0 as valid value)
- event-kill.service.ts: use ?? instead of || for numeric/nullable fields
  across map data builders (presenceTimeSeconds, afkTimeSeconds, etc.)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b1b31d4-cbd3-4f95-92e9-76010be06c63

📥 Commits

Reviewing files that changed from the base of the PR and between f99033e and 19ac480.

📒 Files selected for processing (2)
  • apps/api/scripts/migrate-loots.ts
  • apps/api/src/events/services/event-kill.service.ts

📝 Walkthrough

Walkthrough

This PR refactors two files to consistently use nullish-coalescing (??) instead of logical-OR (||) operators. The change ensures falsy but valid values (such as 0 and empty strings) are preserved rather than coerced to default fallback values.

Changes

Cohort / File(s) Summary
Migration Script
apps/api/scripts/migrate-loots.ts
Updated getItemTypeByCl() to return ITEM_TYPES[cl] directly; adjusted hpp assignment to use nullish-coalescing (??) to preserve zero values.
Kill Event Service
apps/api/src/events/services/event-kill.service.ts
Replaced logical-OR (`

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A shift from OR to the coalescing way,
Zero and empty strings live to fight another day!
Nullish-coalescing hops in with care,
Preserving the truthful values everywhere!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main refactoring change across both modified files: replacing logical-OR with nullish-coalescing operators.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/small-cleanup-20260408

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant