From 3c861c7c0bfa4f3a2aaad0c944ddf5d5324617ff Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 13 Jan 2020 19:09:25 +0100 Subject: [PATCH] internal/prnt: trim trailing comment whitespace (#114) Before printing a comment, remove trailing whitespace. Generation would output `// ` for empty comments. So we trim the whitespace off the end before printing. --- internal/prnt/printer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/prnt/printer.go b/internal/prnt/printer.go index 2239946..410895c 100644 --- a/internal/prnt/printer.go +++ b/internal/prnt/printer.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" "io" + "strings" ) // Generator provides convenience methods for code generators. In particular it @@ -38,7 +39,8 @@ func (g *Generator) NL() { // Comment writes comment lines prefixed with "// ". func (g *Generator) Comment(lines ...string) { for _, line := range lines { - g.Printf("// %s\n", line) + line = strings.TrimSpace("// " + line) + g.Printf("%s\n", line) } }