Skip to content

Commit b6c86a2

Browse files
authored
fix issue 664 (#665)
1 parent 639d12b commit b6c86a2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

rule/nested-structs.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,25 @@ func (l *lintNestedStructs) Visit(n ast.Node) ast.Visitor {
4747
}
4848
return nil
4949
case *ast.Field:
50-
if _, ok := v.Type.(*ast.StructType); ok {
50+
filter := func(n ast.Node) bool {
51+
switch n.(type) {
52+
case *ast.StructType:
53+
return true
54+
default:
55+
return false
56+
}
57+
}
58+
structs := pick(v, filter, nil)
59+
for _, s := range structs {
5160
l.onFailure(lint.Failure{
5261
Failure: "no nested structs are allowed",
5362
Category: "style",
54-
Node: v,
63+
Node: s,
5564
Confidence: 1,
5665
})
57-
break
5866
}
67+
return nil // no need to visit (again) the field
5968
}
69+
6070
return l
6171
}

testdata/nested-structs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ func fred() interface{} {
3030

3131
return s
3232
}
33+
34+
// issue 664
35+
type Bad struct {
36+
Field []struct{} // MATCH /no nested structs are allowed/
37+
}

0 commit comments

Comments
 (0)