diff --git a/mockgen/internal/tests/package_comment/input.go b/mockgen/internal/tests/package_comment/input.go new file mode 100644 index 0000000..a2000e3 --- /dev/null +++ b/mockgen/internal/tests/package_comment/input.go @@ -0,0 +1,5 @@ +package empty_interface + +//go:generate mockgen -package empty_interface -destination mock.go -source input.go -write_package_comment=false + +type Empty interface{} diff --git a/mockgen/internal/tests/package_comment/mock.go b/mockgen/internal/tests/package_comment/mock.go new file mode 100644 index 0000000..8b5a097 --- /dev/null +++ b/mockgen/internal/tests/package_comment/mock.go @@ -0,0 +1,41 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: input.go +// +// Generated by this command: +// +// mockgen -package empty_interface -destination mock.go -source input.go -write_package_comment=false +// + +package empty_interface + +import ( + gomock "go.uber.org/mock/gomock" +) + +// MockEmpty is a mock of Empty interface. +type MockEmpty struct { + ctrl *gomock.Controller + recorder *MockEmptyMockRecorder +} + +// MockEmptyMockRecorder is the mock recorder for MockEmpty. +type MockEmptyMockRecorder struct { + mock *MockEmpty +} + +// NewMockEmpty creates a new mock instance. +func NewMockEmpty(ctrl *gomock.Controller) *MockEmpty { + mock := &MockEmpty{ctrl: ctrl} + mock.recorder = &MockEmptyMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmpty) EXPECT() *MockEmptyMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockEmpty) ISGOMOCK() struct{} { + return struct{}{} +} diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 7fe3770..3ffc9fe 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -395,11 +395,13 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac localNames[pkgName] = true } - if *writePkgComment { - // Ensure there's an empty line before the package to follow the recommendations: - // https://github.com/golang/go/wiki/CodeReviewComments#package-comments - g.p("") + // Ensure there is an empty line between “generated by” block and + // package documentation comments to follow the recommendations: + // https://go.dev/wiki/CodeReviewComments#package-comments + // That is, “generated by” should not be a package comment. + g.p("") + if *writePkgComment { g.p("// Package %v is a generated GoMock package.", outputPkgName) } g.p("package %v", outputPkgName)