@@ -86,15 +86,7 @@ func checkField(pass *analysis.Pass, field *ast.Field, markersAccess markers.Mar
8686
8787func checkIdent (pass * analysis.Pass , ident * ast.Ident , node ast.Node , aliases []* ast.TypeSpec , markersAccess markers.Markers , prefix , marker string , needsMaxLength func (markers.MarkerSet ) bool ) {
8888 if ident .Obj == nil { // Built-in type
89- if ident .Name == "string" {
90- markers := getCombinedMarkers (markersAccess , node , aliases )
91-
92- if needsMaxLength (markers ) {
93- pass .Reportf (node .Pos (), "%s must have a maximum length, add %s marker" , prefix , marker )
94- }
95- }
96-
97- return
89+ checkString (pass , ident , node , aliases , markersAccess , prefix , marker , needsMaxLength )
9890 }
9991
10092 tSpec , ok := ident .Obj .Decl .(* ast.TypeSpec )
@@ -105,6 +97,18 @@ func checkIdent(pass *analysis.Pass, ident *ast.Ident, node ast.Node, aliases []
10597 checkTypeSpec (pass , tSpec , node , append (aliases , tSpec ), markersAccess , fmt .Sprintf ("%s type" , prefix ), marker , needsMaxLength )
10698}
10799
100+ func checkString (pass * analysis.Pass , ident * ast.Ident , node ast.Node , aliases []* ast.TypeSpec , markersAccess markers.Markers , prefix , marker string , needsMaxLength func (markers.MarkerSet ) bool ) {
101+ if ident .Name != "string" {
102+ return
103+ }
104+
105+ markers := getCombinedMarkers (markersAccess , node , aliases )
106+
107+ if needsMaxLength (markers ) {
108+ pass .Reportf (node .Pos (), "%s must have a maximum length, add %s marker" , prefix , marker )
109+ }
110+ }
111+
108112func checkTypeSpec (pass * analysis.Pass , tSpec * ast.TypeSpec , node ast.Node , aliases []* ast.TypeSpec , markersAccess markers.Markers , prefix , marker string , needsMaxLength func (markers.MarkerSet ) bool ) {
109113 if tSpec .Name == nil {
110114 return
@@ -143,13 +147,7 @@ func checkArrayType(pass *analysis.Pass, arrayType *ast.ArrayType, node ast.Node
143147
144148func checkArrayElementIdent (pass * analysis.Pass , ident * ast.Ident , node ast.Node , aliases []* ast.TypeSpec , markersAccess markers.Markers , prefix string ) {
145149 if ident .Obj == nil { // Built-in type
146- if ident .Name == "string" {
147- markers := getCombinedMarkers (markersAccess , node , aliases )
148-
149- if needsItemsMaxLength (markers ) {
150- pass .Reportf (node .Pos (), "%s must have a maximum length, add %s marker" , prefix , kubebuilderItemsMaxLength )
151- }
152- }
150+ checkString (pass , ident , node , aliases , markersAccess , prefix , kubebuilderItemsMaxLength , needsItemsMaxLength )
153151
154152 return
155153 }
0 commit comments