diff --git a/rule/nested-structs.go b/rule/nested-structs.go index cfe9648..deb202e 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 3c6a974..7e5abaf 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/ +}