Skip to content

Commit d7f874f

Browse files
smasher164robpike
authored andcommitted
cmd/go: document convention to signify generated code.
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 <[email protected]>
1 parent 2642df9 commit d7f874f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/cmd/go/alldocs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@
419419
// (gofmt), a fully qualified path (/usr/you/bin/mytool), or a
420420
// command alias, described below.
421421
//
422+
// To convey to humans and machine tools that code is generated,
423+
// generated source should have a line early in the file that
424+
// matches the following regular expression (in Go syntax):
425+
//
426+
// ^// Code generated .* DO NOT EDIT\.$
427+
//
422428
// Note that go generate does not parse the file, so lines that look
423429
// like directives in comments or multiline strings will be treated
424430
// as directives.

src/cmd/go/internal/generate/generate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ that can be run locally. It must either be in the shell path
4747
(gofmt), a fully qualified path (/usr/you/bin/mytool), or a
4848
command alias, described below.
4949
50+
To convey to humans and machine tools that code is generated,
51+
generated source should have a line early in the file that
52+
matches the following regular expression (in Go syntax):
53+
54+
^// Code generated .* DO NOT EDIT\.$
55+
5056
Note that go generate does not parse the file, so lines that look
5157
like directives in comments or multiline strings will be treated
5258
as directives.

0 commit comments

Comments
 (0)