refactor: share compare formatter section builders#84
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors compare-formatters (markdown, report, table) to consume new shared helper builders for best-in-category, deck card grouping, and analysis sections; adds those helpers and types. Also updates backup metadata in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
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)
cmd/cr-api/compare_format_shared.go (1)
66-91: Optional: avoid callinggetEvaluationCategories()twice.The helper is invoked once for the capacity hint and again for iteration, which redundantly rebuilds the slice of structs + closures. Cache it in a local to make the intent clearer and skip one allocation per call.
♻️ Proposed refactor
func buildBestInCategoryEntries(names []string, results []evaluation.EvaluationResult, includeOverall bool) []compareCategoryWinner { - entries := make([]compareCategoryWinner, 0, len(getEvaluationCategories())+1) + categories := getEvaluationCategories() + entries := make([]compareCategoryWinner, 0, len(categories)+1) if includeOverall { bestOverallIdx := findBestOverallDeck(results) entries = append(entries, compareCategoryWinner{ label: "Overall", deckName: names[bestOverallIdx], score: results[bestOverallIdx].OverallScore, rating: string(results[bestOverallIdx].OverallRating), }) } - for _, cat := range getEvaluationCategories() { + for _, cat := range categories { bestIdx := findBestDeckIndex(results, cat.get) bestScore := cat.get(results[bestIdx])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/cr-api/compare_format_shared.go` around lines 66 - 91, In buildBestInCategoryEntries, getEvaluationCategories() is called twice (for the capacity hint and in the loop), causing redundant work and allocations; cache its result in a local variable (e.g., categories := getEvaluationCategories()), use len(categories) for the make capacity, and iterate over categories in the for loop, leaving the rest of the logic (findBestDeckIndex, findBestOverallDeck, and constructing compareCategoryWinner entries) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@cmd/cr-api/compare_format_shared.go`:
- Around line 66-91: In buildBestInCategoryEntries, getEvaluationCategories() is
called twice (for the capacity hint and in the loop), causing redundant work and
allocations; cache its result in a local variable (e.g., categories :=
getEvaluationCategories()), use len(categories) for the make capacity, and
iterate over categories in the for loop, leaving the rest of the logic
(findBestDeckIndex, findBestOverallDeck, and constructing compareCategoryWinner
entries) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aec0aca0-50d3-41e7-9013-eb2b48ef1b36
📒 Files selected for processing (7)
.beads/backup/backup_state.json.beads/backup/events.jsonl.beads/issues.jsonlcmd/cr-api/compare_format_markdown.gocmd/cr-api/compare_format_report.gocmd/cr-api/compare_format_shared.gocmd/cr-api/compare_format_table.go
Summary\n- extract shared compare helpers for best-in-category winner selection, deck card row grouping, and core defense/attack analysis sections\n- refactor table/markdown/report comparison formatters to use shared helpers and remove duplicated loops\n- close beads task
clash-royale-api-o65and record remaining complexity hotspot follow-up asclash-royale-api-o0o\n\n## Validation\n-GOCACHE=/Users/klauer/.codex/worktrees/51ad/clash-royale-api/.cache/go-build GOMODCACHE=/Users/klauer/.codex/worktrees/51ad/clash-royale-api/.cache/gomod go test ./cmd/cr-api\n-GOLANGCI_LINT_CACHE=/Users/klauer/.codex/worktrees/51ad/clash-royale-api/.cache/golangci-lint GOCACHE=/Users/klauer/.codex/worktrees/51ad/clash-royale-api/.cache/go-build GOMODCACHE=/Users/klauer/.codex/worktrees/51ad/clash-royale-api/.cache/gomod golangci-lint run --timeout=5m --enable-only=dupl,gocognit,gocyclo,funlen ./cmd/cr-api/...(triage scan; existing fuzz_commands findings logged in beads)Summary by CodeRabbit
Refactor
Chores