From 47d830f3cd69fee435cf3b00d686681cf551fe4d Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Tue, 10 Mar 2026 15:03:08 +0000 Subject: [PATCH] Forbid usage of omitzero for fields marked optional --- hack/golangci-hints.yaml | 16 ++++++++-------- hack/golangci.yaml | 16 ++++++++-------- hack/kube-api-linter/kube-api-linter.yaml | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/hack/golangci-hints.yaml b/hack/golangci-hints.yaml index e2509203b7b..c4036ca47b8 100644 --- a/hack/golangci-hints.yaml +++ b/hack/golangci-hints.yaml @@ -424,14 +424,14 @@ linters: # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. # nomaps: # policy: AllowStringToStringMaps # Determines how the linter should handle maps of basic types. Maps of objects are always disallowed. - # optionalFields: - # pointers: - # preference: Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`. - # policy: SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`. - # omitempty: - # policy: SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`. - # omitzero: - # policy: SuggestFix | Warn | Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. + optionalFields: + pointers: + preference: Always # Whether to always require pointers, or only when required. Defaults to `Always`. + policy: SuggestFix # The policy for pointers in optional fields. Defaults to `SuggestFix`. + omitempty: + policy: SuggestFix # The policy for omitempty in optional fields. Defaults to `SuggestFix`. + omitzero: + policy: Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. # optionalOrRequired: # preferredOptionalMarker: optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. # preferredRequiredMarker: required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. diff --git a/hack/golangci.yaml b/hack/golangci.yaml index e2386fc5255..721901c841d 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -437,14 +437,14 @@ linters: # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. # nomaps: # policy: AllowStringToStringMaps # Determines how the linter should handle maps of basic types. Maps of objects are always disallowed. - # optionalFields: - # pointers: - # preference: Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`. - # policy: SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`. - # omitempty: - # policy: SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`. - # omitzero: - # policy: SuggestFix | Warn | Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. + optionalFields: + pointers: + preference: Always # Whether to always require pointers, or only when required. Defaults to `Always`. + policy: SuggestFix # The policy for pointers in optional fields. Defaults to `SuggestFix`. + omitempty: + policy: SuggestFix # The policy for omitempty in optional fields. Defaults to `SuggestFix`. + omitzero: + policy: Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. # optionalOrRequired: # preferredOptionalMarker: optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. # preferredRequiredMarker: required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`. diff --git a/hack/kube-api-linter/kube-api-linter.yaml b/hack/kube-api-linter/kube-api-linter.yaml index fe60a59f59b..0819f428457 100644 --- a/hack/kube-api-linter/kube-api-linter.yaml +++ b/hack/kube-api-linter/kube-api-linter.yaml @@ -51,14 +51,14 @@ lintersConfig: # jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case. # nomaps: # policy: AllowStringToStringMaps # Determines how the linter should handle maps of basic types. Maps of objects are always disallowed. - # optionalFields: - # pointers: - # preference: Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`. - # policy: SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`. - # omitempty: - # policy: SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`. - # omitzero: - # policy: SuggestFix | Warn | Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. + optionalFields: + pointers: + preference: Always # Whether to always require pointers, or only when required. Defaults to `Always`. + policy: SuggestFix # The policy for pointers in optional fields. Defaults to `SuggestFix`. + omitempty: + policy: SuggestFix # The policy for omitempty in optional fields. Defaults to `SuggestFix`. + omitzero: + policy: Forbid # The policy for omitzero in optional fields. Defaults to `SuggestFix`. # optionalOrRequired: # preferredOptionalMarker: optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`. # preferredRequiredMarker: required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.