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

Commit 2b692ab

Browse files
mueslipoy
authored andcommittedSep 30, 2019
Simplified Go code
- Replaced range loops with an append - No need to specify slice capacity that's equal to the length
1 parent 176c208 commit 2b692ab

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed
 

‎mockgen/mockgen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (g *generator) Generate(pkg *model.Package, pkgName string, outputPackagePa
269269
}
270270

271271
// Sort keys to make import alias generation predictable
272-
sortedPaths := make([]string, len(im), len(im))
272+
sortedPaths := make([]string, len(im))
273273
x := 0
274274
for pth := range im {
275275
sortedPaths[x] = pth

‎mockgen/parse.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *ast.InterfaceType) (*m
250250
}
251251
// Copy the methods.
252252
// TODO: apply shadowing rules.
253-
for _, m := range eintf.Methods {
254-
intf.Methods = append(intf.Methods, m)
255-
}
253+
intf.Methods = append(intf.Methods, eintf.Methods...)
256254
case *ast.SelectorExpr:
257255
// Embedded interface in another package.
258256
fpkg, sel := v.X.(*ast.Ident).String(), v.Sel.String()
@@ -278,9 +276,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *ast.InterfaceType) (*m
278276
}
279277
// Copy the methods.
280278
// TODO: apply shadowing rules.
281-
for _, m := range eintf.Methods {
282-
intf.Methods = append(intf.Methods, m)
283-
}
279+
intf.Methods = append(intf.Methods, eintf.Methods...)
284280
default:
285281
return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type)
286282
}

0 commit comments

Comments
 (0)