Skip to content

fix: separate the templ version comment from the package clause - #1459

Merged
a-h merged 2 commits into
a-h:mainfrom
dannyshafer:fix-1457-version-comment-godoc
Oct 20, 2026
Merged

a-h merged 2 commits into
a-h:mainfrom
dannyshafer:fix-1457-version-comment-godoc

Conversation

@dannyshafer

Copy link
Copy Markdown
Contributor

templ generate writes // templ: version: ... (and // templ: generated: ... when a timestamp is requested) directly above the package clause, so Go treats these comments as package documentation. In a package that also has a hand-written package comment, golangci-lint's godoclint then reports "package has more than one godoc" on the hand-written file, which generated-file exclusions don't suppress.

This writes a blank line after the version/generated date comments when either is present, as suggested in the issue. Output without a version or timestamp (e.g. -include-version=false) is unchanged, so none of the checked-in _templ.go files change.

Fixes #1457

Testing

  • Added TestGeneratorVersionCommentIsNotPackageDoc in generator/generator_test.go: it generates code with a version (and with a version plus timestamp), parses the output with go/parser, and asserts there is no package doc. It fails without the change.
  • go run ./cmd/templ generate -include-version=false produces no diff; go test -short ./... passes; go vet and golangci-lint run ./generator/... report no issues.

This change was prepared with AI assistance (Claude Code).

…a-h#1457

The version and generated date comments were written directly above the
package clause, so Go treated them as package documentation. A hand-written
package comment in the same package then made linters such as godoclint
report more than one package doc. Write a blank line after these comments
when either is present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@a-h

a-h commented Oct 20, 2026

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

@a-h
a-h merged commit fa302d6 into a-h:main Oct 20, 2026
@a-h

a-h commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks good spot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated files attach the "// templ: version" comment to the package clause as package documentation

3 participants