Skip to content

Commit

Permalink
fix issue 664 (mgechev#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava authored and subham-deepsource committed Apr 8, 2022
1 parent b38bf82 commit 8f8bbf5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rule/nested-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions testdata/nested-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ func fred() interface{} {

return s
}

// issue 664
type Bad struct {
Field []struct{} // MATCH /no nested structs are allowed/
}

0 comments on commit 8f8bbf5

Please sign in to comment.