From de80859ba5eef96508f64481944afae06d35805e Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Tue, 26 Mar 2024 12:54:21 +0300 Subject: [PATCH] =?UTF-8?q?Do=20not=20expose=20=E2=80=9CCode=20generated?= =?UTF-8?q?=20by=E2=80=9D=20block=20in=20package=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/tests/package_comment/input.go | 5 +++ .../internal/tests/package_comment/mock.go | 41 +++++++++++++++++++ mockgen/mockgen.go | 10 +++-- 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 mockgen/internal/tests/package_comment/input.go create mode 100644 mockgen/internal/tests/package_comment/mock.go 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)