Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/enumr/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"fmt"
"go/format"
"strings"
"text/template"
)
Expand Down Expand Up @@ -42,7 +43,14 @@ func generateEnumSource(
return nil, fmt.Errorf("failed to execute template: %w", err)
}

return buf.Bytes(), nil
// Run the generated source through gofmt so callers always receive
// canonically formatted output, regardless of template whitespace.
formatted, err := format.Source(buf.Bytes())
if err != nil {
return nil, fmt.Errorf("failed to format generated source: %w", err)
}

return formatted, nil
}

func renderInit(instance instanceData, fields []fieldInfo) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/enumr/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func TestGenerateEnumSourceWithVars(t *testing.T) {
}

expectedSnippet := `var (
CreditCard = PaymentMethod{ Code: "CC", Desc: "Credit Card" }
PayPal = PaymentMethod{ Code: "PP", Desc: "PayPal" }
CreditCard = PaymentMethod{Code: "CC", Desc: "Credit Card"}
PayPal = PaymentMethod{Code: "PP", Desc: "PayPal"}
)`

if !strings.Contains(string(source), expectedSnippet) {
Expand Down
1 change: 0 additions & 1 deletion pkg/enumr/testdata/myenum_enum.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ func MyEnumValues() []MyEnum {
ValueTwo,
}
}

Loading