You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reportShouldRemovePointer(pass, field, PointersPolicySuggestFix, fieldName, "field %s underlying type does not need to be a pointer. The pointer should be removed.", fieldName)
220
-
casePointersPolicyWarn:
221
-
pass.Reportf(field.Pos(), "field %s underlying type does not need to be a pointer. The pointer should be removed.", fieldName)
reportShouldRemovePointer(pass, field, PointersPolicySuggestFix, fieldName, "field %s underlying type does not need to be a pointer. The pointer should be removed.", fieldName)
237
+
casePointersPolicyWarn:
238
+
pass.Reportf(field.Pos(), "field %s underlying type does not need to be a pointer. The pointer should be removed.", fieldName)
s.reportShouldAddPointerMessage(pass, field, fieldName, "with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil (unset) from empty.")
ArrayWithZeroMinItems []string`json:"arrayWithZeroMinItems"`// want "field ArrayWithZeroMinItems should have the omitempty tag."
19
+
ArrayWithZeroMinItems []string`json:"arrayWithZeroMinItems"`// want "field ArrayWithZeroMinItems should have the omitempty tag." "field ArrayWithZeroMinItems with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
ArrayWithZeroMinItemsWithOmitEmpty []string`json:"arrayWithZeroMinItemsWithOmitEmpty,omitempty"`// want "field ArrayWithZeroMinItemsWithOmitEmpty with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
23
23
24
24
ByteArray []byte`json:"byteArray"`// want "field ByteArray should have the omitempty tag."
ArrayWithZeroMinItems []string `json:"arrayWithZeroMinItems,omitempty"` // want "field ArrayWithZeroMinItems should have the omitempty tag."
19
+
ArrayWithZeroMinItems *[]string `json:"arrayWithZeroMinItems,omitempty"` // want "field ArrayWithZeroMinItems should have the omitempty tag." "field ArrayWithZeroMinItems with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
ArrayWithZeroMinItemsWithOmitEmpty *[]string `json:"arrayWithZeroMinItemsWithOmitEmpty,omitempty"` // want "field ArrayWithZeroMinItemsWithOmitEmpty with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
23
23
24
24
ByteArray []byte `json:"byteArray,omitempty"` // want "field ByteArray should have the omitempty tag."
MapWithZeroMinPropertiesmap[string]string`json:"mapWithZeroMinProperties"`// want "field MapWithZeroMinProperties should have the omitempty tag."
19
+
MapWithZeroMinPropertiesmap[string]string`json:"mapWithZeroMinProperties"`// want "field MapWithZeroMinProperties should have the omitempty tag." "field MapWithZeroMinProperties with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
MapWithZeroMinPropertiesWithOmitEmptymap[string]string`json:"mapWithZeroMinPropertiesWithOmitEmpty,omitempty"`// want "field MapWithZeroMinPropertiesWithOmitEmpty with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
MapWithZeroMinProperties map[string]string `json:"mapWithZeroMinProperties,omitempty"` // want "field MapWithZeroMinProperties should have the omitempty tag."
19
+
MapWithZeroMinProperties *map[string]string `json:"mapWithZeroMinProperties,omitempty"` // want "field MapWithZeroMinProperties should have the omitempty tag." "field MapWithZeroMinProperties with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
MapWithZeroMinPropertiesWithOmitEmpty *map[string]string `json:"mapWithZeroMinPropertiesWithOmitEmpty,omitempty"` // want "field MapWithZeroMinPropertiesWithOmitEmpty with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
MapPtrWithZeroMinPropertiesNoOmitEmpty*map[string]string`json:"mapPtrWithZeroMinPropertiesNoOmitEmpty"`// want "field MapPtrWithZeroMinPropertiesNoOmitEmpty should have the omitempty tag."
23
+
24
+
// Non-pointer version should suggest adding pointer
25
+
// +kubebuilder:validation:MinProperties=0
26
+
MapWithZeroMinPropertiesNoPtrmap[string]string`json:"mapWithZeroMinPropertiesNoPtr,omitempty"`// want "field MapWithZeroMinPropertiesNoPtr with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
27
+
}
28
+
29
+
// Test that slices WITHOUT pointers are flagged when MinItems is zero
30
+
typeTestSliceWithMinZeroAlwaysstruct {
31
+
// +kubebuilder:validation:MinItems=0
32
+
ArrayWithZeroMinItemsNoPtr []string`json:"arrayWithZeroMinItemsNoPtr,omitempty"`// want "field ArrayWithZeroMinItemsNoPtr with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
17
33
}
18
34
19
35
// Test that pointers ARE still flagged when MinItems/MinProperties is NOT zero
MapPtrWithZeroMinPropertiesNoOmitEmpty *map[string]string `json:"mapPtrWithZeroMinPropertiesNoOmitEmpty,omitempty"` // want "field MapPtrWithZeroMinPropertiesNoOmitEmpty should have the omitempty tag."
23
+
24
+
// Non-pointer version should suggest adding pointer
25
+
// +kubebuilder:validation:MinProperties=0
26
+
MapWithZeroMinPropertiesNoPtr *map[string]string `json:"mapWithZeroMinPropertiesNoPtr,omitempty"` // want "field MapWithZeroMinPropertiesNoPtr with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
27
+
}
28
+
29
+
// Test that slices WITHOUT pointers are flagged when MinItems is zero
30
+
type TestSliceWithMinZeroAlways struct {
31
+
// +kubebuilder:validation:MinItems=0
32
+
ArrayWithZeroMinItemsNoPtr *[]string `json:"arrayWithZeroMinItemsNoPtr,omitempty"` // want "field ArrayWithZeroMinItemsNoPtr with MinItems=0/MinProperties=0, underlying type should be a pointer to distinguish nil \\(unset\\) from empty."
17
33
}
18
34
19
35
// Test that pointers ARE still flagged when MinItems/MinProperties is NOT zero
Copy file name to clipboardExpand all lines: pkg/analysis/utils/serialization/testdata/src/pointers_when_required/pointer_to_slice_with_minzero.go.golden
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
package a
2
2
3
3
type TestPointerToSliceWithMinZero struct {
4
+
// Pointer to slice with MinItems=0 allows distinguishing:
0 commit comments