Skip to content

[function-namer] Go function rename plan: pkg/sliceutil #31685

@github-actions

Description

@github-actions

Go Function Rename Plan

Package Analyzed: pkg/sliceutil
Analysis Date: 2026-05-12
Round-Robin Position: package 13 of 23 total packages
Functions Analyzed: 8 functions across 1 file

Why This Matters

When AI coding agents search for functions to complete a task, they rely on function
names to understand what code does. Clear, descriptive names increase the likelihood
that an agent will find the right function instead of reimplementing existing logic.
Functions in the same package also call each other, so reviewing them together gives
better context for rename decisions.

Rename Suggestions

pkg/sliceutil/sliceutil.go
Current Name Suggested Name Reason
MapToSlice[K comparable, V any](m map[K]V) []K MapKeys[K comparable, V any](m map[K]V) []K MapToSlice is ambiguous — it sounds like “convert a map to a slice” without telegraphing whether the slice contains keys, values, or [K,V] pairs. The function actually returns only the keys. MapKeys mirrors Go’s stdlib maps.Keys and matches how agents phrase the intent (“get the keys of a map as a slice”). 14 call sites confirm it’s a high-traffic helper where a clearer name pays off.

All functions in pkg/sliceutil/sliceutil.go (for reference):

  • Filter[T any] — ✅ Universal FP name, immediately recognizable. No change.
  • Map[T, U any] — ✅ Universal FP name. No change.
  • MapToSlice[K, V]⚠️ Rename suggested (see table above).
  • FilterMapKeys[K, V] — ✅ Accurately describes “filter and return map keys”. No change.
  • Any[T any] — ✅ Standard FP name; matches slices.ContainsFunc semantics. No change.
  • Deduplicate[T comparable] — ✅ Clear verb describing the action. No change.
  • MergeUnique[T comparable] — ✅ Clearly reads as “merge while keeping unique items”. No change.
  • Exclude[T comparable] — ✅ Clear verb. No change.

🤖 Agentic Implementation Plan

Agentic Implementation Plan

This issue is designed to be assigned to a coding agent. The agent should implement
the single rename suggestion below in one focused pull request.

Prerequisites

  • Verify the rename is semantically accurate by reviewing the function body in pkg/sliceutil/sliceutil.go
  • Confirm no Go interface declares a method named MapToSlice that would constrain the rename (it’s a top-level generic free function, so this should be safe)

Implementation Steps

1. Rename the function in pkg/sliceutil/sliceutil.go
// Old
func MapToSlice[K comparable, V any](m map[K]V) []K {

// New
func MapKeys[K comparable, V any](m map[K]V) []K {

Update the function’s doc comment to lead with MapKeys and clarify it returns map keys as a slice with undefined order.

2. Update all call sites

Find every caller — there are 14 in production code plus README/docs references:

grep -rn "sliceutil\.MapToSlice\b" pkg/ --include="*.go"
grep -rn "sliceutil\.MapToSlice\b" docs/ pkg/sliceutil/README.md

Known call sites at time of analysis:

  • pkg/cli/firewall_log.go (2 calls, lines 357–358)
  • pkg/cli/audit_report_render_guard.go (line 47)
  • pkg/cli/run_push.go (line 120)
  • pkg/cli/gateway_logs_render.go (lines 159, 189)
  • pkg/workflow/mcp_setup_generator.go (lines 404, 439, 546, 619, 737)
  • pkg/workflow/yaml_env_helpers.go (line 38)
  • pkg/workflow/mcp_config_custom.go (lines 364, 457, 474)
  • Plus any test files that exercise the helper (grep -rn "MapToSlice" pkg/)
  • pkg/sliceutil/README.md if MapToSlice is mentioned
3. Verify compilation after the rename
make build
4. Run tests and lints after the rename
make test-unit
make lint

Commit Convention

refactor: rename sliceutil.MapToSlice to MapKeys for clarity

Validation Checklist

  • Function renamed in pkg/sliceutil/sliceutil.go and doc comment updated
  • All 14+ call sites updated across pkg/cli/ and pkg/workflow/
  • Test files updated (if any reference MapToSlice)
  • pkg/sliceutil/README.md updated if it mentions the old name
  • make build passes with no errors
  • make test-unit passes
  • make lint passes
  • PR description explains the agent-discoverability rationale (matches Go’s maps.Keys convention)

Notes for the Agent

  • This is a pure rename refactor — behavior must not change, only the name.
  • If any call site reveals a name collision (e.g., a local MapKeys variable in the same scope), pick a minimal local rename for the variable; do not rebrand the helper.
  • Follow existing naming conventions documented in AGENTS.md.
  • The other 7 functions in pkg/sliceutil (Filter, Map, FilterMapKeys, Any, Deduplicate, MergeUnique, Exclude) were reviewed and intentionally left as-is — do not rename them in the same PR.

Generated by the Daily Go Function Namer workflow
Run: §25733896422

References:

Generated by Daily Go Function Namer · ● 3.6M ·

  • expires on May 19, 2026, 12:23 PM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions