Description
pkg/cli/audit_comparison.go defines two near-identical structs — AuditComparisonIntDelta (line 45) and AuditComparisonStringDelta (line 51) — that share the same {Before, After, Changed} shape. The only difference is the element type (int vs string). This is a textbook case for a Go generic type.
Suggested Changes
type Delta[T any] struct {
Before T `json:"before"`
After T `json:"after"`
Changed bool `json:"changed"`
}
// type AuditComparisonIntDelta = Delta[int]
// type AuditComparisonStringDelta = Delta[string]
- Define a single
Delta[T any] struct in pkg/cli/audit_comparison.go
- Replace both existing structs with type aliases or update all usages to use
Delta[int] / Delta[string] directly
- The generic type trivially extends to
Delta[float64] or other types for future needs
Files Affected
pkg/cli/audit_comparison.go (lines 45-60, replace two structs with single generic)
- Any files in
pkg/cli/ that reference AuditComparisonIntDelta or AuditComparisonStringDelta
Success Criteria
Effort
~1 hr · S
Source
Extracted from Typist — Go Type Consistency Analysis discussion #45983
Priority
Medium — removes copy-paste drift and enables future extension
🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · 156.6 AIC · ⌖ 7.84 AIC · ⊞ 7K · ◷
Description
pkg/cli/audit_comparison.godefines two near-identical structs —AuditComparisonIntDelta(line 45) andAuditComparisonStringDelta(line 51) — that share the same{Before, After, Changed}shape. The only difference is the element type (intvsstring). This is a textbook case for a Go generic type.Suggested Changes
Delta[T any]struct inpkg/cli/audit_comparison.goDelta[int]/Delta[string]directlyDelta[float64]or other types for future needsFiles Affected
pkg/cli/audit_comparison.go(lines 45-60, replace two structs with single generic)pkg/cli/that referenceAuditComparisonIntDeltaorAuditComparisonStringDeltaSuccess Criteria
Delta[T any]generic type definedmake fmt && make golint-custom && go test ./pkg/cli/...passesEffort
~1 hr · S
Source
Extracted from Typist — Go Type Consistency Analysis discussion #45983
Priority
Medium — removes copy-paste drift and enables future extension