Skip to content

Commit

Permalink
Do not expose “Code generated by” block in package comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tie committed Mar 26, 2024
1 parent c9ae04c commit de80859
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
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

0 comments on commit de80859

Please sign in to comment.