Skip to content

refactor: share compare formatter section builders#84

Merged
klauern merged 6 commits intomainfrom
codex/refactor-compare-shared-sections
Apr 22, 2026
Merged

refactor: share compare formatter section builders#84
klauern merged 6 commits intomainfrom
codex/refactor-compare-shared-sections

Conversation

@klauern
Copy link
Copy Markdown
Owner

@klauern klauern commented Apr 21, 2026

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-o65 and record remaining complexity hotspot follow-up as clash-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

    • Reorganized comparison report formatting for improved readability and consistency.
    • Improved deck composition display with grouped card rows and better alignment.
    • Simplified analysis section presentation to render core sections generically.
    • Streamlined best-in-category champion rendering across outputs.
  • Chores

    • Updated backup metadata.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 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: d1c57fd9-baec-4a3b-a8c7-1b872d8e9ec1

📥 Commits

Reviewing files that changed from the base of the PR and between 00430da and 95941c0.

📒 Files selected for processing (1)
  • cmd/cr-api/compare_format_shared.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/cr-api/compare_format_shared.go

📝 Walkthrough

Walkthrough

Refactors 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 .beads/backup/backup_state.json (commit ID and timestamp).

Changes

Cohort / File(s) Summary
Backup State Metadata
.beads/backup/backup_state.json
Updated last_dolt_commit to a new commit ID and timestamp to a later ISO8601 datetime; no other structural changes.
Shared formatter helpers
cmd/cr-api/compare_format_shared.go
Added unexported types compareCategoryWinner and compareAnalysisSection plus helpers: buildBestInCategoryEntries() (best-overall + per-category winners), groupDeckCards() (chunk deck into rows), and buildCoreAnalysisSections() (construct Defense/Attack sections).
Formatter refactors (markdown/report/table)
cmd/cr-api/compare_format_markdown.go, cmd/cr-api/compare_format_report.go, cmd/cr-api/compare_format_table.go
Replaced inline best-in-category logic with buildBestInCategoryEntries(); switched deck rendering to groupDeckCards(...,4) row-wise output; replaced explicit Defense/Attack rendering with iteration over buildCoreAnalysisSections() for generic analysis section output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰
I hopped through lines both crisp and bright,
Grouped cards in rows and crowned the right,
Built tiny helpers, neat and spry,
And updated timestamps passing by,
A joyful thump — the formats sigh.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: extracting and sharing compare formatter section builders across multiple files to reduce duplication.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 codex/refactor-compare-shared-sections
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch codex/refactor-compare-shared-sections

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/cr-api/compare_format_shared.go (1)

66-91: Optional: avoid calling getEvaluationCategories() 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

📥 Commits

Reviewing files that changed from the base of the PR and between d58aa39 and 00430da.

📒 Files selected for processing (7)
  • .beads/backup/backup_state.json
  • .beads/backup/events.jsonl
  • .beads/issues.jsonl
  • cmd/cr-api/compare_format_markdown.go
  • cmd/cr-api/compare_format_report.go
  • cmd/cr-api/compare_format_shared.go
  • cmd/cr-api/compare_format_table.go

@klauern klauern merged commit f36d74a into main Apr 22, 2026
9 checks passed
@klauern klauern deleted the codex/refactor-compare-shared-sections branch April 22, 2026 15:19
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