refactor(cli/seed): consistent crypto.randomInt() and nullish coalescing#712
refactor(cli/seed): consistent crypto.randomInt() and nullish coalescing#712kamilwronka wants to merge 1 commit intodevelopfrom
Conversation
…sh coalescing Replace Math.random() with crypto.randomInt() in battles-generator and npcs-scraper for consistency with the rest of the seed generators. Change color || 0 to color ?? 0 in guild-generator for correct nullish handling. 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. |
📝 WalkthroughWalkthroughThe pull request replaces JavaScript's standard Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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)
packages/cli/src/commands/seed/generators/battles-generator.ts (1)
34-39: Replace||with??(or remove fallback entirely).Line 39 currently uses
randomWorld || "gordion". Given the localworldslist and Line 34 selection, this fallback is unnecessary; if you keep it, use??for consistency.Proposed cleanup
- return { + return { accountId, characterId, - world: randomWorld || "gordion", + world: randomWorld, events: this.samplePayload.events, };As per coding guidelines, "Prefer
??over||for nullish coalescing".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/commands/seed/generators/battles-generator.ts` around lines 34 - 39, The return currently sets world: randomWorld || "gordion", which uses || fallback unnecessarily; update the assignment to either remove the fallback entirely or use nullish coalescing (world: randomWorld ?? "gordion") so that the code uses ?? instead of ||; locate the randomWorld variable (set from worlds[crypto.randomInt(0, worlds.length)]) and update the world property in the returned object accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cli/src/commands/seed/generators/battles-generator.ts`:
- Around line 34-39: The return currently sets world: randomWorld || "gordion",
which uses || fallback unnecessarily; update the assignment to either remove the
fallback entirely or use nullish coalescing (world: randomWorld ?? "gordion") so
that the code uses ?? instead of ||; locate the randomWorld variable (set from
worlds[crypto.randomInt(0, worlds.length)]) and update the world property in the
returned object accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 172075af-e9dd-4917-8e82-a11ec3b161f9
📒 Files selected for processing (3)
packages/cli/src/commands/seed/generators/battles-generator.tspackages/cli/src/commands/seed/generators/guild-generator.tspackages/cli/src/commands/seed/scrapers/npcs-scraper.ts
Summary
Math.random()withcrypto.randomInt()inbattles-generator.tsandnpcs-scraper.tsfor consistency with other seed generators (loot-generator,guild-generator) that already usecrypto.randomInt()color || 0tocolor ?? 0inguild-generator.tsfor correct nullish handling (avoids false-positive on0values, though none exist in current data)Files touched
packages/cli/src/commands/seed/generators/battles-generator.tspackages/cli/src/commands/seed/generators/guild-generator.tspackages/cli/src/commands/seed/scrapers/npcs-scraper.tsWhy these changes are safe
crypto.randomInt(0, n)produces the same range[0, n)asMath.floor(Math.random() * n)— no behavioral change??vs||only differs for falsy-but-non-nullish values (0,"",false);ROLE_COLORScontains no such values, so behavior is identicalResidual risks
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit