From 3bec63661309acb2aa920929ea1ae94c179331d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Thu, 22 May 2025 08:27:20 +0200 Subject: [PATCH] statusoptional: Embed nil check in checkStatusStruct Return early from the method when statusType is nil, as we can't reliably expect all callers to check for passed arguments before calling the function. Hopefully fixes https://github.com/kubernetes-sigs/kube-api-linter/issues/90 --- pkg/analysis/statusoptional/analyzer.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/analysis/statusoptional/analyzer.go b/pkg/analysis/statusoptional/analyzer.go index f84584b2..1abbaa9d 100644 --- a/pkg/analysis/statusoptional/analyzer.go +++ b/pkg/analysis/statusoptional/analyzer.go @@ -85,10 +85,6 @@ func (a *analyzer) run(pass *analysis.Pass) (any, error) { } statusStructType := getStructFromField(pass, field) - if statusStructType == nil { - return - } - a.checkStatusStruct(pass, statusStructType, markersAccess, jsonTags) }) @@ -96,7 +92,7 @@ func (a *analyzer) run(pass *analysis.Pass) (any, error) { } func (a *analyzer) checkStatusStruct(pass *analysis.Pass, statusType *ast.StructType, markersAccess markershelper.Markers, jsonTags extractjsontags.StructFieldTags) { - if statusType.Fields == nil || statusType.Fields.List == nil { + if statusType == nil || statusType.Fields == nil || statusType.Fields.List == nil { return }