diff --git a/gomock/internal/mock_gomock/mock_matcher.go b/gomock/internal/mock_gomock/mock_matcher.go index d1cff723..f4a6d526 100644 --- a/gomock/internal/mock_gomock/mock_matcher.go +++ b/gomock/internal/mock_gomock/mock_matcher.go @@ -5,8 +5,9 @@ package mock_gomock import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockMatcher is a mock of Matcher interface. diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go index fc38a1c4..e5326c80 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go @@ -5,9 +5,10 @@ package bugreport import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" faux "github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" - reflect "reflect" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go index bfd9aafa..c0fe30c2 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go @@ -5,9 +5,10 @@ package greeter import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" client "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" - reflect "reflect" ) // MockInputMaker is a mock of InputMaker interface. diff --git a/mockgen/internal/tests/dot_imports/mock.go b/mockgen/internal/tests/dot_imports/mock.go index 359ed296..6e46eab9 100644 --- a/mockgen/internal/tests/dot_imports/mock.go +++ b/mockgen/internal/tests/dot_imports/mock.go @@ -7,9 +7,10 @@ package dot_imports import ( bytes "bytes" . "context" - gomock "github.com/golang/mock/gomock" . "net/http" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockWithDotImports is a mock of WithDotImports interface. diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go index 3f76db0a..8eca8644 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go @@ -5,8 +5,9 @@ package bugreport import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go index ea21a4af..4cc17e95 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go @@ -5,10 +5,11 @@ package bugreport import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" ersatz "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz" ersatz0 "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" - reflect "reflect" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/import_embedded_interface/net_mock.go b/mockgen/internal/tests/import_embedded_interface/net_mock.go index 70bb9aa4..07792a6d 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/net_mock.go @@ -5,9 +5,10 @@ package bugreport import ( - gomock "github.com/golang/mock/gomock" http "net/http" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockNet is a mock of Net interface. diff --git a/mockgen/internal/tests/import_source/definition/source_mock.go b/mockgen/internal/tests/import_source/definition/source_mock.go index a99d9be1..b3d58d76 100644 --- a/mockgen/internal/tests/import_source/definition/source_mock.go +++ b/mockgen/internal/tests/import_source/definition/source_mock.go @@ -5,8 +5,9 @@ package source import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/import_source/source_mock.go b/mockgen/internal/tests/import_source/source_mock.go index 149f6624..46677a31 100644 --- a/mockgen/internal/tests/import_source/source_mock.go +++ b/mockgen/internal/tests/import_source/source_mock.go @@ -5,9 +5,10 @@ package mock_source import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" source "github.com/golang/mock/mockgen/internal/tests/import_source/definition" - reflect "reflect" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go index bdb6949a..967c4b59 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go @@ -5,9 +5,10 @@ package mock_pkg import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" - reflect "reflect" ) // MockIntf is a mock of Intf interface. diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go index 7914cd3d..2e61bae4 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go @@ -5,9 +5,10 @@ package mock_pkg import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" - reflect "reflect" ) // MockArg is a mock of Arg interface. diff --git a/mockgen/internal/tests/mock_in_test_package/mock_test.go b/mockgen/internal/tests/mock_in_test_package/mock_test.go index e0e9ac2a..4d598f03 100644 --- a/mockgen/internal/tests/mock_in_test_package/mock_test.go +++ b/mockgen/internal/tests/mock_in_test_package/mock_test.go @@ -5,9 +5,10 @@ package users_test import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" mock_in_test_package "github.com/golang/mock/mockgen/internal/tests/mock_in_test_package" - reflect "reflect" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/self_package/mock.go b/mockgen/internal/tests/self_package/mock.go index 581eef4d..72e2cfa8 100644 --- a/mockgen/internal/tests/self_package/mock.go +++ b/mockgen/internal/tests/self_package/mock.go @@ -5,8 +5,9 @@ package core import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockMethods is a mock of Methods interface. diff --git a/mockgen/internal/tests/test_package/mock_test.go b/mockgen/internal/tests/test_package/mock_test.go index e363d644..cc35b43d 100644 --- a/mockgen/internal/tests/test_package/mock_test.go +++ b/mockgen/internal/tests/test_package/mock_test.go @@ -5,8 +5,9 @@ package users_test import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/unexported_method/bugreport_mock.go b/mockgen/internal/tests/unexported_method/bugreport_mock.go index 00d664af..d52d06ec 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_mock.go +++ b/mockgen/internal/tests/unexported_method/bugreport_mock.go @@ -5,8 +5,9 @@ package bugreport import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/vendor_dep/mock.go b/mockgen/internal/tests/vendor_dep/mock.go index 78572a23..4900ac08 100644 --- a/mockgen/internal/tests/vendor_dep/mock.go +++ b/mockgen/internal/tests/vendor_dep/mock.go @@ -5,9 +5,10 @@ package vendor_dep import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" present "golang.org/x/tools/present" - reflect "reflect" ) // MockVendorsDep is a mock of VendorsDep interface. diff --git a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go index 5ba118c6..b02a0489 100644 --- a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go +++ b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go @@ -5,9 +5,10 @@ package mock_vendor_dep import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" present "golang.org/x/tools/present" - reflect "reflect" ) // MockVendorsDep is a mock of VendorsDep interface. diff --git a/mockgen/internal/tests/vendor_pkg/mock.go b/mockgen/internal/tests/vendor_pkg/mock.go index e8b25a59..f0a41968 100644 --- a/mockgen/internal/tests/vendor_pkg/mock.go +++ b/mockgen/internal/tests/vendor_pkg/mock.go @@ -5,8 +5,9 @@ package vendor_pkg import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockElem is a mock of Elem interface. diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index f8d1d555..ce483f87 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -24,7 +24,6 @@ import ( "flag" "fmt" "go/build" - "go/format" "go/token" "io" "io/ioutil" @@ -39,6 +38,8 @@ import ( "unicode" "github.com/golang/mock/mockgen/model" + + toolsimports "golang.org/x/tools/imports" ) const ( @@ -151,6 +152,7 @@ func main() { g.srcPackage = packageName g.srcInterfaces = flag.Arg(1) } + g.destination = *destination if *mockNames != "" { g.mockNames = parseMockNames(*mockNames) @@ -210,6 +212,7 @@ type generator struct { indent string mockNames map[string]string // may be empty filename string // may be empty + destination string // may be empty srcPackage, srcInterfaces string // may be empty copyrightHeader string @@ -617,7 +620,7 @@ func (o identifierAllocator) allocateIdentifier(want string) string { // Output returns the generator's output, formatted in the standard Go style. func (g *generator) Output() []byte { - src, err := format.Source(g.buf.Bytes()) + src, err := toolsimports.Process(g.destination, g.buf.Bytes(), nil) if err != nil { log.Fatalf("Failed to format generated source code: %s\n%s", err, g.buf.String()) } diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index f975a351..301a5bf3 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -5,8 +5,9 @@ package mock_concurrent import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockMath is a mock of Math interface. diff --git a/sample/mock_user/mock_user.go b/sample/mock_user/mock_user.go index 2ab051d1..95dd7470 100644 --- a/sample/mock_user/mock_user.go +++ b/sample/mock_user/mock_user.go @@ -7,17 +7,18 @@ package mock_sample import ( bufio "bufio" bytes "bytes" - gomock "github.com/golang/mock/gomock" - imp1 "github.com/golang/mock/sample/imp1" - imp2 "github.com/golang/mock/sample/imp2" - imp3 "github.com/golang/mock/sample/imp3" - imp_four "github.com/golang/mock/sample/imp4" hash "hash" template "html/template" io "io" http "net/http" reflect "reflect" template0 "text/template" + + gomock "github.com/golang/mock/gomock" + imp1 "github.com/golang/mock/sample/imp1" + imp2 "github.com/golang/mock/sample/imp2" + imp3 "github.com/golang/mock/sample/imp3" + imp_four "github.com/golang/mock/sample/imp4" ) // MockIndex is a mock of Index interface.