From 8f8bbf5f88e025bffeb1abe61f572aaa032f9560 Mon Sep 17 00:00:00 2001 From: chavacava Date: Thu, 31 Mar 2022 17:40:26 +0200 Subject: [PATCH] fix issue 664 (#665) --- rule/nested-structs.go | 16 +++++++++++++--- testdata/nested-structs.go | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/rule/nested-structs.go b/rule/nested-structs.go index 1068ef824..a9403bacc 100644 --- a/rule/nested-structs.go +++ b/rule/nested-structs.go @@ -47,15 +47,25 @@ func (l *lintNestedStructs) Visit(n ast.Node) ast.Visitor { } return nil case *ast.Field: - if _, ok := v.Type.(*ast.StructType); ok { + filter := func(n ast.Node) bool { + switch n.(type) { + case *ast.StructType: + return true + default: + return false + } + } + structs := pick(v, filter, nil) + for _, s := range structs { l.onFailure(lint.Failure{ Failure: "no nested structs are allowed", Category: "style", - Node: v, + Node: s, Confidence: 1, }) - break } + return nil // no need to visit (again) the field } + return l } diff --git a/testdata/nested-structs.go b/testdata/nested-structs.go index 3c6a97416..7e5abafaf 100644 --- a/testdata/nested-structs.go +++ b/testdata/nested-structs.go @@ -30,3 +30,8 @@ func fred() interface{} { return s } + +// issue 664 +type Bad struct { + Field []struct{} // MATCH /no nested structs are allowed/ +}