fix: detach file comments from package declaration#442
Merged
alecthomas merged 1 commit intoalecthomas:masterfrom Jul 2, 2025
Merged
fix: detach file comments from package declaration#442alecthomas merged 1 commit intoalecthomas:masterfrom
alecthomas merged 1 commit intoalecthomas:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR ensures a blank line is emitted between the generated‐file comment/build constraint and the package declaration to prevent linters from mis-associating the comment as package documentation.
- Changed the template’s
{{end -}}to{{end}}and added an explicit blank line - Always emit a newline before
package {{.Package}}, regardless of.Tags
Comments suppressed due to low confidence (2)
cmd/participle/codegen.go.tmpl:1
- Consider adding a unit test that renders this template with and without
.Tagsto verify the blank line appears correctly in both cases.
// Code generated by Participle. DO NOT EDIT. alecthomas approved these changes Jul 2, 2025
Owner
| Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The lexer source file auto-generated by
cmd/participleoutputs the package declaration immediately after:DO NOT EDITcomment recognized by Go tools, andIn both cases, many linters/analyzers end up attaching the comment line (but not the constraints directive) to the package clause as its documentation. This is then flagged as improper grammar in some way.
For example,
staticcheckraises a warning (ST1000):The best official guidance I can find to support the proposed change comes from
go help buildconstraint, which states:With this change applied, the resulting output includes a single line break between the build constraint and package declaration:
Both GitHub Copilot and Google's AI Mode suggest adding another line break between the comment and directive:
But I can't find any Go documentation recommending this.
Currently, there isn't any way to actually add a package comment to the generated source file. It would be neat if
cmd/participleaccepted a flag that would insert a comment between the proposed line break and package declaration, e.g.: