Skip to content

Commit 3af531b

Browse files
authored
Merge pull request #201 from saschagrunert/fix-lint
Extract string literal into constant
2 parents 74c4ae9 + 319c4de commit 3af531b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/analysis/utils/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"sigs.k8s.io/kube-api-linter/pkg/markers"
3030
)
3131

32+
const stringTypeName = "string"
33+
3234
// IsBasicType checks if the type of the given identifier is a basic type.
3335
// Basic types are types like int, string, bool, etc.
3436
func IsBasicType(pass *analysis.Pass, expr ast.Expr) bool {
@@ -46,7 +48,7 @@ func IsStringType(pass *analysis.Pass, expr ast.Expr) bool {
4648
return false
4749
}
4850

49-
if ident.Name == "string" {
51+
if ident.Name == stringTypeName {
5052
return true
5153
}
5254

pkg/analysis/utils/zero_value.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func isStructZeroValueValid(pass *analysis.Pass, field *ast.Field, structType *a
103103

104104
// Check if this struct should be validated as a string (Type=string marker).
105105
// This handles structs with custom marshalling that serialize as strings.
106-
if GetTypeMarkerValue(pass, field, markersAccess) == "string" {
106+
if GetTypeMarkerValue(pass, field, markersAccess) == stringTypeName {
107107
// Use string validation logic instead of struct validation logic.
108108
// This ensures that string-specific validation markers (MinLength, MaxLength, Pattern)
109109
// are properly evaluated for structs that marshal as strings.
@@ -456,7 +456,7 @@ func isIntegerIdent(ident *ast.Ident) bool {
456456

457457
// isStringIdent checks if the identifier is a string type.
458458
func isStringIdent(ident *ast.Ident) bool {
459-
return ident.Name == "string"
459+
return ident.Name == stringTypeName
460460
}
461461

462462
// isBoolIdent checks if the identifier is a boolean type.

0 commit comments

Comments
 (0)