[go: up one dir, main page]

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

Commit

Permalink
Format generated files with goimports (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
timebertt authored Jul 31, 2020
1 parent 9cb0a11 commit 8734ec5
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 26 deletions.
3 changes: 2 additions & 1 deletion gomock/internal/mock_gomock/mock_matcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/dot_imports/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/import_embedded_interface/net_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/import_source/source_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/mock_in_test_package/mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/self_package/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/test_package/mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/unexported_method/bugreport_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/vendor_dep/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mockgen/internal/tests/vendor_pkg/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"flag"
"fmt"
"go/build"
"go/format"
"go/token"
"io"
"io/ioutil"
Expand All @@ -39,6 +38,8 @@ import (
"unicode"

"github.com/golang/mock/mockgen/model"

toolsimports "golang.org/x/tools/imports"
)

const (
Expand Down Expand Up @@ -151,6 +152,7 @@ func main() {
g.srcPackage = packageName
g.srcInterfaces = flag.Arg(1)
}
g.destination = *destination

if *mockNames != "" {
g.mockNames = parseMockNames(*mockNames)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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())
}
Expand Down
3 changes: 2 additions & 1 deletion sample/concurrent/mock/concurrent_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions sample/mock_user/mock_user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8734ec5

Please sign in to comment.