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.
This commit is contained in:
Klaus Post
2020-01-13 19:09:25 +01:00
committed by Michael McLoughlin
parent 205fc6a3d7
commit 3c861c7c0b

View File

@@ -5,6 +5,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"strings"
) )
// Generator provides convenience methods for code generators. In particular it // Generator provides convenience methods for code generators. In particular it
@@ -38,7 +39,8 @@ func (g *Generator) NL() {
// Comment writes comment lines prefixed with "// ". // Comment writes comment lines prefixed with "// ".
func (g *Generator) Comment(lines ...string) { func (g *Generator) Comment(lines ...string) {
for _, line := range lines { for _, line := range lines {
g.Printf("// %s\n", line) line = strings.TrimSpace("// " + line)
g.Printf("%s\n", line)
} }
} }