Skip to content

feat(registry): implement IsZeroer for Variants#4742

Merged
suzuki-shunsuke merged 1 commit into
mainfrom
feat/variants-iszero
Apr 30, 2026
Merged

feat(registry): implement IsZeroer for Variants#4742
suzuki-shunsuke merged 1 commit into
mainfrom
feat/variants-iszero

Conversation

@suzuki-shunsuke

@suzuki-shunsuke suzuki-shunsuke commented Apr 30, 2026

Copy link
Copy Markdown
Member

Summary

Adds an IsZero method to the Variants slice type so it follows the same pattern as the sibling collection types in pkg/config/registry/package_info.go (Overrides, FormatOverrides, Replacements), all of which implement go.yaml.in/yaml/v3.IsZeroer.

Why

Variants was added in #4733 as a named slice type — type Variants []*Variant — but it was the only collection type in the package without an IsZero method. That made the API surface inconsistent with how the rest of the package opts into yaml.v3's zero detection.

go.yaml.in/yaml/v3 calls IsZero() bool during marshal to decide whether a field tagged with omitempty should be emitted. The other collection types in this file each implement it the same way:

// IsZero implements the [go.yaml.in/yaml/v3.IsZeroer] interface.
// It returns true if the Overrides slice is nil.
func (o Overrides) IsZero() bool {
    return o == nil
}

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 explicit IsZeroer implementation, behaviour relied on the encoder's reflect-based fallback, which differs subtly from the other collection types — they only treat nil as empty (so an explicit Variants{} would be marshalled as variants: []), while reflection considers a length-0 slice zero too.

What changed

pkg/config/registry/package_info.go:

 // Variants is a list of Variant conditions that must all match for the
 // containing Override to apply.
 type Variants []*Variant

+// IsZero implements the [go.yaml.in/yaml/v3.IsZeroer] interface.
+// It returns true if the Variants slice is nil.
+func (v Variants) IsZero() bool {
+	return v == nil
+}
+
 // Override provides platform-specific package configuration that overrides

That's the entire diff — 6 lines, single file.

Test plan

  • cmdx v (go vet) — passes
  • cmdx l (golangci-lint) — 0 issues
  • go test -count=1 ./pkg/config/registry/... — passes
  • Manual: re-emit a registry that contains variants via aqua generate-registry and confirm nil Variants are omitted while explicit empty [] would still be emitted (matches Overrides/FormatOverrides semantics).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved YAML configuration serialization to omit empty variant configurations from output files, resulting in cleaner and more readable configuration files.

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>
@suzuki-shunsuke suzuki-shunsuke added this to the v2.58.0 milestone Apr 30, 2026
@suzuki-shunsuke suzuki-shunsuke enabled auto-merge (squash) April 30, 2026 06:53
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c41ef62c-d1fc-4fd4-a9dd-33dabb8206e2

📥 Commits

Reviewing files that changed from the base of the PR and between 48112d7 and d06c03b.

📒 Files selected for processing (1)
  • pkg/config/registry/package_info.go

📝 Walkthrough

Walkthrough

An IsZero() method was added to the Variants slice type to enable YAML v3 to correctly identify and omit nil variant values during marshaling operations.

Changes

Cohort / File(s) Summary
YAML Marshaling Support
pkg/config/registry/package_info.go
Added IsZero() method to Variants type to support YAML v3 zero-value detection during marshaling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A method small, yet precise,
Makes YAML marshals oh-so-nice!
When nil variants come to play,
IsZero() clears the way! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing the IsZeroer interface for the Variants type to make it consistent with other collection types in the file.
Description check ✅ Passed The description is comprehensive and well-structured, covering the summary, rationale, changes made, and test plan. It follows the repository's contribution guidelines and provides clear context for the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/variants-iszero

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@suzuki-shunsuke suzuki-shunsuke merged commit f9e487d into main Apr 30, 2026
21 of 22 checks passed
@suzuki-shunsuke suzuki-shunsuke deleted the feat/variants-iszero branch April 30, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant