mirror of
https://github.com/mgechev/revive.git
synced 2025-07-15 01:04:40 +02:00
fix issue 664 (#665)
This commit is contained in:
@ -47,15 +47,25 @@ func (l *lintNestedStructs) Visit(n ast.Node) ast.Visitor {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case *ast.Field:
|
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{
|
l.onFailure(lint.Failure{
|
||||||
Failure: "no nested structs are allowed",
|
Failure: "no nested structs are allowed",
|
||||||
Category: "style",
|
Category: "style",
|
||||||
Node: v,
|
Node: s,
|
||||||
Confidence: 1,
|
Confidence: 1,
|
||||||
})
|
})
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
return nil // no need to visit (again) the field
|
||||||
}
|
}
|
||||||
|
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
5
testdata/nested-structs.go
vendored
5
testdata/nested-structs.go
vendored
@ -30,3 +30,8 @@ func fred() interface{} {
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 664
|
||||||
|
type Bad struct {
|
||||||
|
Field []struct{} // MATCH /no nested structs are allowed/
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user