Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not expose “Code generated by” block in package comments #168

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mockgen/internal/tests/package_comment/input.go
Original file line number Diff line number Diff line change
@@ -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{}
41 changes: 41 additions & 0 deletions mockgen/internal/tests/package_comment/mock.go

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

10 changes: 6 additions & 4 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading