uber-go/mock

Generating mocks on a file with a dot import creates a compilation error

a-canya opened this issue · 0 comments

Actual behavior When generatinga mock from a source file which contains a dot import, the dot import is copied in the destination file. If the dot import is not actually used, the compiler then fails.

Expected behavior Generated code always compiles, even if someone decides to add a dot import in their code.

To Reproduce I created an example of the issue here.

  1. Have mockgen installed.
  2. Clone this repo or copy the following code into a main.go file:
    import . "fmt"
    
    //go:generate mockgen -source=main.go -destination=mocks/main.go
    type I interface{}
    
    func main() {
        /* fmt. */ Println("Hello world!")
    }
  3. Run go generate ./...
  4. Run go build ./... - the compilation fails with error: mocks/main.go:13:2: "fmt" imported and not used.

Additional Information

  • gomock mode (reflect or source): source (I haven't tried withe reflect, issue might also happen)
  • gomock version or git ref: v0.4.0
  • golang version: 1.21.4

Triage Notes for the Maintainers

Workaround

The easy and sane workaround that I will apply is just to not have dot imports. I thought it was still useful to report the bug though...