From fcf2fe509ef2b2e1802d08210deaf7e625a988c3 Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 12 Aug 2026 01:17:41 -0400 Subject: [PATCH] fix(events): keep every line of a doc comment inside a comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit genevents prefixed only the *first* line of a const block's doc comment with `//`, so a comment that ran to a second paragraph emitted bare prose into the TypeScript object literal — a generated file that does not parse. Nothing had noticed because nobody had run the generator since the comments were written, and `make generate` is a pre-commit hook: the failure was waiting for whoever next touched a .sql, a .templ or an event constant. A generator is only verified by running it. --- backend/events/cmd/genevents/main.go | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/events/cmd/genevents/main.go b/backend/events/cmd/genevents/main.go index d83467a..494cd7f 100644 --- a/backend/events/cmd/genevents/main.go +++ b/backend/events/cmd/genevents/main.go @@ -120,6 +120,28 @@ func cleanComment(s string) string { return s } +// commentLines renders a doc comment as indented TypeScript line +// comments, one per source line. +func commentLines(comment string) []string { + if comment == "" { + return nil + } + + var out []string + + for _, line := range strings.Split(comment, "\n") { + if line == "" { + out = append(out, " //") + + continue + } + + out = append(out, " // "+line) + } + + return out +} + // generateTypeScript produces the full TypeScript source from the parsed // constant groups. func generateTypeScript(groups []constGroup) string { @@ -130,8 +152,12 @@ func generateTypeScript(groups []constGroup) string { b.WriteString("export const Events = {\n") for i, g := range groups { - if g.Comment != "" { - b.WriteString(" // " + g.Comment + "\n") + // Every line, not just the first: a doc comment that runs to a + // second paragraph used to emit its remainder as bare prose + // inside the object literal, so `make generate` — a pre-commit + // hook — produced TypeScript that does not parse. + for _, line := range commentLines(g.Comment) { + b.WriteString(line + "\n") } for _, c := range g.Consts {