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
@@ -119,7 +118,7 @@ func reportArrayOfStructIssue(pass *analysis.Pass, field *ast.Field) {
119
118
prefix=fieldName
120
119
}
121
120
122
-
message:=fmt.Sprintf("%s is an array of structs, but the struct has no required fields. At least one field should be marked as %s to prevent ambiguous YAML configurations", prefix, markers.RequiredMarker)
121
+
message:=fmt.Sprintf("%s is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations", prefix)
Copy file name to clipboardExpand all lines: pkg/analysis/arrayofstruct/testdata/src/a/a.go
+25-7Lines changed: 25 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ type ValidPrimitiveArray struct {
57
57
// Invalid cases - arrays of structs without any required fields
58
58
59
59
typeInvalidStructstruct {
60
-
Items []InvalidItem// want "InvalidStruct.Items is an array of structs, but the struct has no required fields"
60
+
Items []InvalidItem// want "InvalidStruct.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
61
61
}
62
62
63
63
typeInvalidItemstruct {
@@ -69,7 +69,7 @@ type InvalidItem struct {
69
69
}
70
70
71
71
typeInvalidStructWithPointerstruct {
72
-
Items []*InvalidPointerItem// want "InvalidStructWithPointer.Items is an array of structs, but the struct has no required fields"
72
+
Items []*InvalidPointerItem// want "InvalidStructWithPointer.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
73
73
}
74
74
75
75
typeInvalidPointerItemstruct {
@@ -79,7 +79,7 @@ type InvalidPointerItem struct {
79
79
80
80
typeInvalidStructWithInlineStructstruct {
81
81
// Inline struct definitions should also be checked
82
-
Items []struct { // want "InvalidStructWithInlineStruct.Items is an array of structs, but the struct has no required fields"
82
+
Items []struct { // want "InvalidStructWithInlineStruct.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
83
83
// +optional
84
84
Namestring
85
85
}
@@ -88,7 +88,7 @@ type InvalidStructWithInlineStruct struct {
88
88
// Invalid case - struct with no markers at all
89
89
90
90
typeInvalidStructNoMarkersstruct {
91
-
Items []InvalidItemNoMarkers// want "InvalidStructNoMarkers.Items is an array of structs, but the struct has no required fields"
91
+
Items []InvalidItemNoMarkers// want "InvalidStructNoMarkers.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
92
92
}
93
93
94
94
typeInvalidItemNoMarkersstruct {
@@ -115,20 +115,38 @@ type AllRequiredItem struct {
115
115
typeItemAlias=InvalidItem
116
116
117
117
typeInvalidStructWithAliasstruct {
118
-
Items []ItemAlias// want "InvalidStructWithAlias.Items is an array of structs, but the struct has no required fields"
118
+
Items []ItemAlias// want "InvalidStructWithAlias.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
119
119
}
120
120
121
121
// Test with array type alias
122
122
123
123
typeArrayAlias= []InvalidItem
124
124
125
125
typeInvalidStructWithArrayAliasstruct {
126
-
ItemsArrayAlias// want "InvalidStructWithArrayAlias.Items is an array of structs, but the struct has no required fields"
126
+
ItemsArrayAlias// want "InvalidStructWithArrayAlias.Items is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
127
127
}
128
128
129
129
// Valid case with multiple array fields
130
130
131
131
typeValidMultipleArraysstruct {
132
132
ValidItems []ValidItem
133
-
InvalidItems []InvalidItem// want "ValidMultipleArrays.InvalidItems is an array of structs, but the struct has no required fields"
133
+
InvalidItems []InvalidItem// want "ValidMultipleArrays.InvalidItems is an array of structs, but the struct has no required fields. At least one field should be marked as required to prevent ambiguous YAML configurations"
134
+
}
135
+
136
+
// Valid case - type alias to basic type (should not trigger linter)
137
+
138
+
typeStringAlias=string
139
+
140
+
typeValidStructWithBasicTypeAliasstruct {
141
+
// This should not trigger the linter because StringAlias resolves to string, a basic type
142
+
Items []StringAlias
143
+
}
144
+
145
+
// Valid case - custom type wrapping basic type (should not trigger linter)
146
+
147
+
typeCustomStringstring
148
+
149
+
typeValidStructWithCustomBasicTypestruct {
150
+
// This should not trigger the linter because CustomString is based on string, a basic type
0 commit comments