mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
fix issue 664 (#665)
This commit is contained in:
parent
639d12bb4f
commit
b6c86a274f
@ -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
|
||||
}
|
||||
|
5
testdata/nested-structs.go
vendored
5
testdata/nested-structs.go
vendored
@ -30,3 +30,8 @@ func fred() interface{} {
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// issue 664
|
||||
type Bad struct {
|
||||
Field []struct{} // MATCH /no nested structs are allowed/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user