feat(registry): implement IsZeroer for Variants#4742
Conversation
Add an IsZero method to the Variants slice type so it follows the same
pattern as the sibling collection types (Overrides, FormatOverrides,
Replacements) in this package — they all implement
go.yaml.in/yaml/v3.IsZeroer to give marshal-time control over when the
field is omitted from generated YAML.
Without this method, an explicit empty Variants{} would be treated
identically to the type's reflect-based zero, while a nil Variants
remained the same. Matching the sibling pattern keeps the behavior
predictable and uniform when a registry that uses Variants is
re-emitted by aqua tooling such as `aqua generate-registry`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAn Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Summary
Adds an
IsZeromethod to theVariantsslice type so it follows the same pattern as the sibling collection types inpkg/config/registry/package_info.go(Overrides,FormatOverrides,Replacements), all of which implementgo.yaml.in/yaml/v3.IsZeroer.Why
Variantswas added in #4733 as a named slice type —type Variants []*Variant— but it was the only collection type in the package without anIsZeromethod. That made the API surface inconsistent with how the rest of the package opts into yaml.v3's zero detection.go.yaml.in/yaml/v3callsIsZero() boolduring marshal to decide whether a field tagged withomitemptyshould be emitted. The other collection types in this file each implement it the same way:The encoder is exercised by, for example,
pkg/controller/generate-registry/generate.go(yaml.NewEncoder(c.stdout, yaml.IndentSequence(true))) when aqua re-emits registry YAML. Without an explicitIsZeroerimplementation, behaviour relied on the encoder's reflect-based fallback, which differs subtly from the other collection types — they only treatnilas empty (so an explicitVariants{}would be marshalled asvariants: []), while reflection considers a length-0 slice zero too.What changed
pkg/config/registry/package_info.go:That's the entire diff — 6 lines, single file.
Test plan
cmdx v(go vet) — passescmdx l(golangci-lint) — 0 issuesgo test -count=1 ./pkg/config/registry/...— passesvariantsviaaqua generate-registryand confirmnilVariants are omitted while explicit empty[]would still be emitted (matchesOverrides/FormatOverridessemantics).🤖 Generated with Claude Code
Summary by CodeRabbit