Skip to content

[Code Quality] Replace AuditComparisonIntDelta/StringDelta with generic Delta[T] type #46001

Description

@github-actions

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

  • Single Delta[T any] generic type defined
  • Both old concrete types removed or made type aliases
  • All existing usages compile correctly
  • make fmt && make golint-custom && go test ./pkg/cli/... passes
  • JSON serialization is unchanged

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 ·

  • expires on Jul 17, 2026, 5:23 AM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions