Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Simplified Go code
Browse files Browse the repository at this point in the history
- Replaced range loops with an append
- No need to specify slice capacity that's equal to the length
  • Loading branch information
muesli authored and poy committed Sep 30, 2019
1 parent 176c208 commit 2b692ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (g *generator) Generate(pkg *model.Package, pkgName string, outputPackagePa
}

// Sort keys to make import alias generation predictable
sortedPaths := make([]string, len(im), len(im))
sortedPaths := make([]string, len(im))
x := 0
for pth := range im {
sortedPaths[x] = pth
Expand Down
8 changes: 2 additions & 6 deletions mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *ast.InterfaceType) (*m
}
// Copy the methods.
// TODO: apply shadowing rules.
for _, m := range eintf.Methods {
intf.Methods = append(intf.Methods, m)
}
intf.Methods = append(intf.Methods, eintf.Methods...)
case *ast.SelectorExpr:
// Embedded interface in another package.
fpkg, sel := v.X.(*ast.Ident).String(), v.Sel.String()
Expand All @@ -278,9 +276,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *ast.InterfaceType) (*m
}
// Copy the methods.
// TODO: apply shadowing rules.
for _, m := range eintf.Methods {
intf.Methods = append(intf.Methods, m)
}
intf.Methods = append(intf.Methods, eintf.Methods...)
default:
return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type)
}
Expand Down

0 comments on commit 2b692ab

Please # to comment.