Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document standard way to recognize machine generated files #25433

Closed
nhooyr opened this issue May 17, 2018 · 6 comments
Closed

docs: document standard way to recognize machine generated files #25433

nhooyr opened this issue May 17, 2018 · 6 comments

Comments

@nhooyr
Copy link
Contributor

nhooyr commented May 17, 2018

in #13560 (comment) bradfitz said the wiki would be edited but I can't seem to find anything on the wiki or even googling golang standard comment on machine generated files. Only the original issue comes up. We should document it somewhere appropriate.

Maybe https://blog.golang.org/generate could be updated to mention it?

@smasher164
Copy link
Member

Additionally, I think the go tool documentation is a good place to mention this.
https://golang.org/cmd/go/#hdr-Generate_Go_files_by_processing_source
Something along the lines of:

To convey to humans and machine tools that code is generated, outputted source should have a line in the file that matches the following regular expression (in Go syntax):
^// Code generated .* DO NOT EDIT\.$

@dmitshur
Copy link
Contributor

in #13560 (comment) bradfitz said the wiki would be edited but I can't seem to find anything on the wiki

He said:

The wiki seems like it would just be edited by somebody without discussion.

Meaning that the wiki might not be an appropriate place to put it, since it can be edited by anyone.

The current canonical documentation is the comment by Rob Pike in that issue, with the https://golang.org/s/generatedcode link pointing to it.

@nhooyr
Copy link
Contributor Author

nhooyr commented May 24, 2018

Meaning that the wiki might not be an appropriate place to put it, since it can be edited by anyone.

Ah, I interpreted it as the wiki would be edited to link to Rob's comment without any need for a discussion.

@ianlancetaylor ianlancetaylor changed the title document standard way to recognize machine generated files docs: document standard way to recognize machine generated files May 31, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone May 31, 2018
@gopherbot
Copy link

Change https://golang.org/cl/118756 mentions this issue: cmd/go: document convention to signify generated code.

gopherbot pushed a commit that referenced this issue Jun 14, 2018
This change updates the go tool's documentation under the section
"Generate Go files by processing source" to mention the convention that
generated source files should have a line of text that matches the
following regular expression:

    ^// Code generated .* DO NOT EDIT\.$

Previously, the canonical documentation for this convention
(https://golang.org/s/generatedcode) referenced Rob Pike's comment at
https://golang.org/issue/13560#issuecomment-288457920. This change
merely moves that information to a more visible place.

Updates #25433.

Change-Id: I804d95d307d1dc68cb28da3750ebe9090178c474
Reviewed-on: https://go-review.googlesource.com/118756
Reviewed-by: Rob Pike <r@golang.org>
@robpike
Copy link
Contributor

robpike commented Jun 14, 2018

Closed by https://golang.org/cl/118756

@robpike robpike closed this as completed Jun 14, 2018
@gopherbot
Copy link

Change https://golang.org/cl/158817 mentions this issue: cmd/go: copy missing bit of documentation about code generated comment

gopherbot pushed a commit that referenced this issue Jan 22, 2019
This CL attempts to restore the clarity of the original specification
at https://golang.org/s/generatedcode that the line may appear
anywhere. It is preferable (for human readability), and most common
for it to be early in the file, but that is merely a convention, not
a strict well-specified requirement. Document it as so.

Background

Issue #13560 was a proposal define a standard for marking files as
generated, one that is suitable to be recognized both by humans
and machine tools. It was accepted, and the final specification
was documented at https://golang.org/s/generatedcode. Its text,
copied exactly:

	Generated files are marked by a line of text that matches
	the regular expression, in Go syntax:

		^// Code generated .* DO NOT EDIT\.$

	The .* means the tool can put whatever folderol it wants in there,
	but the comment must be a single line and must start with Code generated
	and end with DO NOT EDIT., with a period.

	The text may appear anywhere in the file.

The https://golang.org/s/generatedcode link points to a comment
in a very large GitHub issue. That makes it harder to find.
Issue #25433 was opened about moving that information somewhere else.
It was resolved via CL 118756, which added text to cmd/go documentation
at https://golang.org/cmd/go/#hdr-Generate_Go_files_by_processing_source:

	To convey to humans and machine tools that code is generated,
	generated source should have a line early in the file that
	matches the following regular expression (in Go syntax):

		^// Code generated .* DO NOT EDIT\.$

The CL description noted that "This change merely moves that
information to a more visible place." The intention was to preserve
the specification unmodified.

The original specification was very clear that "The text may appear
anywhere in the file." The new text in cmd/go documentation wasn't
very clear. "A line early in the file" is not a precise enough criteria
to be recognized by a machine tool, because there isn't a precise
definition of what lines are "early in the file".

Updates #13560
Updates #25433
Updates #28089

Change-Id: I4e374163b16c3f972f9591ec2647fd3d5a2dd5ae
Reviewed-on: https://go-review.googlesource.com/c/158817
Reviewed-by: Rob Pike <r@golang.org>
@golang golang locked and limited conversation to collaborators Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants