golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 610 forks source link

Mockgen should create package names without under_scores #537

Closed hongshaoyang closed 3 years ago

hongshaoyang commented 3 years ago

Requested feature

By default, Mockgen creates package names with mock_ concatenated with the package of the input file.

This goes against guidelines, as documented in https://blog.golang.org/package-names:

Good package names are short and clear. They are lower case, with no under_scores or mixedCaps.

And in Effective Go: MixedCaps:

[The] convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.

(Optional) Proposed solution

By default, Mockgen should create package names with mock concatenated with the package of the input file.

KlausVii commented 3 years ago

Since package names are not camelCased, adding words into them is bit finicky, hence usually trying to keep them one word etc. Using _ is already established in things like package_test, so I don't see any reason to change this.

Besides -package= lets you set it whatever you like...

codyoss commented 3 years ago

I think the underscore notation is okay for mock. As @KlausVii points out you can change the default with a flag. I personally always manually specify the package flag. Every project is a little different and I don't think there is a good "one" solution here. Closing since this is overridable.