Skip to content

Commit 1a28f2c

Browse files
committed
Enable optionalfields linter
1 parent 51ab638 commit 1a28f2c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.golangci-kal.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ linters:
2222
- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
2323
- "nobools" # Bools do not evolve over time, should use enums instead.
2424
- "nofloats" # Ensure floats are not used.
25+
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
26+
# having the `omitempty` value in their `json` tag where appropriate.
2527
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2628
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
2729
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
@@ -44,6 +46,12 @@ linters:
4446
# optionalOrRequired:
4547
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
4648
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
49+
optionalFields:
50+
pointers:
51+
preference: Always # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
52+
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
53+
omitempty:
54+
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
4755
# requiredFields:
4856
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers.
4957

hack/tools/.custom-gcl.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ version: v2.1.0
22
name: golangci-lint-kube-api-linter
33
destination: ./bin
44
plugins:
5-
- module: 'sigs.k8s.io/kube-api-linter'
6-
version: v0.0.0-20250515061849-37102c8f17a9
5+
- module: sigs.k8s.io/kube-api-linter
6+
path: ../../../kube-api-linter

0 commit comments

Comments
 (0)