Repository navigation
fix(render): gofmt generated source before returning - #17
Merged
Merged
Conversation
The generator emitted raw template output, which is not guaranteed to be gofmt-clean (extra spaces inside struct literals, unaligned `=` in var blocks, trailing blank line). Downstream repos that run `gofmt -l` in CI then fail on the generated enum files. Run the template output through go/format so callers always receive canonically formatted code, independent of template whitespace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Run the enumr template output through
go/format(gofmt) ingenerateEnumSourcebefore returning it.Why
The generator previously returned raw
text/templateoutput, which is not guaranteed to be gofmt-clean. In practice it produced:SortByBehavior{ name: "..." }instead ofSortByBehavior{name: "..."}=in generatedvar (...)blocksDownstream repos (e.g.
shipt/search) that enforcegofmt -lin CI then fail on the committed generated enum files. Formatting at generation time makes output canonical and robust to template whitespace, so consumers never have to hand-fix or re-gofmt generated code.Changes
pkg/enumr/render.go: runformat.Source()on the buffer, wrapping errors with%w.pkg/enumr/render_test.go: update the var-block snippet assertion to the gofmt-canonical form (no inner-brace spaces, aligned=).pkg/enumr/testdata/myenum_enum.go.golden: regenerated (drops trailing blank line).Testing
go test -race ./...— passgofmt -l .— cleango generate ./...produces no diff (deterministic, matches CI "Verify Clean Generation")