Problem
pkg/workflow/domains.go repeats the same 4-line "map-as-set to sorted slice" idiom 8 times:
domainMap := make(map[string]bool)
// ... fill domainMap ...
result := make([]string, 0, len(domainMap))
for d := range domainMap {
result = append(result, d)
}
sort.Strings(result)
return result
Locations (all in pkg/workflow/domains.go)
| Function |
Line |
getEcosystemDomains (compound path) |
291 |
getDomainsFromRuntimes |
346 |
GetAllowedDomains |
452 |
GetBlockedDomains |
643 |
GetAPITargetDomains |
799 |
mergeAPITargetDomains |
877 |
expandAllowedDomains |
956 |
expandAllowedDomains (second map) |
983 |
Impact
- Severity: Medium
- Maintainability: New domain functions copy the same boilerplate rather than calling a utility
- Consistency: The rest of the codebase already uses the idiomatic replacement —
slices.Sorted(maps.Keys(...)) — at pkg/workflow/compiler_main_job.go:99 and pkg/cli/run_workflow_validation.go:240
Recommendation
Add "maps" and "slices" to the import block in domains.go and replace each 4-line collect-and-sort block with a single expression:
// Before (4 lines):
result := make([]string, 0, len(domainMap))
for d := range domainMap {
result = append(result, d)
}
sort.Strings(result)
// After (1 line):
result := slices.Sorted(maps.Keys(domainMap))
The sort import can be removed from domains.go once all 8 occurrences are replaced (verify no other sort.* calls remain).
Also update the similar pattern in sortedMapKeys in pkg/workflow/map_helpers.go (which converts map[string]string keys) to use slices.Sorted(maps.Keys(m)).
Before / After Example (getEcosystemDomains)
// Before
domainMap := make(map[string]bool)
for _, component := range components {
for _, d := range getEcosystemDomains(component) {
domainMap[d] = true
}
}
result := make([]string, 0, len(domainMap))
for d := range domainMap {
result = append(result, d)
}
sort.Strings(result)
return result
// After
domainMap := make(map[string]bool)
for _, component := range components {
for _, d := range getEcosystemDomains(component) {
domainMap[d] = true
}
}
return slices.Sorted(maps.Keys(domainMap))
Validation
Estimated Effort: Small
Generated by Sergo - Serena Go Expert · ● 630.9K · ◷
Problem
pkg/workflow/domains.gorepeats the same 4-line "map-as-set to sorted slice" idiom 8 times:Locations (all in
pkg/workflow/domains.go)getEcosystemDomains(compound path)getDomainsFromRuntimesGetAllowedDomainsGetBlockedDomainsGetAPITargetDomainsmergeAPITargetDomainsexpandAllowedDomainsexpandAllowedDomains(second map)Impact
slices.Sorted(maps.Keys(...))— atpkg/workflow/compiler_main_job.go:99andpkg/cli/run_workflow_validation.go:240Recommendation
Add
"maps"and"slices"to the import block indomains.goand replace each 4-line collect-and-sort block with a single expression:The
sortimport can be removed fromdomains.goonce all 8 occurrences are replaced (verify no othersort.*calls remain).Also update the similar pattern in
sortedMapKeysinpkg/workflow/map_helpers.go(which convertsmap[string]stringkeys) to useslices.Sorted(maps.Keys(m)).Before / After Example (
getEcosystemDomains)Validation
go build ./pkg/workflow/passesgo test ./pkg/workflow/...passesgolangci-lint run ./pkg/workflow/shows no new warningsEstimated Effort: Small