petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
253 stars 28 forks source link

Comments and formatting #60

Closed danilvpetrov closed 6 years ago

danilvpetrov commented 6 years ago

Hi @petergtz,

This change is about making generated mock and matcher files a bit friendlier for pre-commit checks with tools like golint and gofmt. The code in changes adds comments to each generated type/method, uses a format tool to run formatting changes after each file is generated. User can specify tools gofmt, goimports, and goreturns with -f flag to format generated files. If no parameter with -f flag is specified, the tool defaults to gofmt.

Relevant unit test is included.

Hopefully you find these changes useful. Output from golint complaining about the formats of generated files can be really overwhelming.

petergtz commented 6 years ago

Hi @danilvpetrov,

Thanks a lot for this PR. Is this really just to silence golint? If so, golint actually ignores generated code, but the headers of pegomock-generated files do not match what golint scans for.

golint follows this standard pattern for generated code.

See here for its implementation: https://github.com/golang/lint/blob/master/lint.go#L117-L133

So maybe it's enough to just change that header from

// Automatically generated by pegomock. DO NOT EDIT!

to

// Code generated by pegomock. DO NOT EDIT.

What do you think?

danilvpetrov commented 6 years ago

Yep, looks like changing header in generated files will do the trick. I'll remove all the changes and place a new with new header PR fairly soon.

danilvpetrov commented 6 years ago

Hi @petergtz,

Removed previous changes, added required comments to the file generation output. Could you please review?

petergtz commented 6 years ago

Very nice! Thanks again, @danilvpetrov!