From d7f874fef66483d6d123ffb9853bfa58d29dc94a Mon Sep 17 00:00:00 2001 From: Akhil Indurti Date: Wed, 13 Jun 2018 20:52:05 -0400 Subject: [PATCH] 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 --- src/cmd/go/alldocs.go | 6 ++++++ src/cmd/go/internal/generate/generate.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index d37942b738..ffc6505c1d 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -419,6 +419,12 @@ // (gofmt), a fully qualified path (/usr/you/bin/mytool), or a // command alias, described below. // +// 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\.$ +// // Note that go generate does not parse the file, so lines that look // like directives in comments or multiline strings will be treated // as directives. diff --git a/src/cmd/go/internal/generate/generate.go b/src/cmd/go/internal/generate/generate.go index 441f91aea8..971844d2ea 100644 --- a/src/cmd/go/internal/generate/generate.go +++ b/src/cmd/go/internal/generate/generate.go @@ -47,6 +47,12 @@ that can be run locally. It must either be in the shell path (gofmt), a fully qualified path (/usr/you/bin/mytool), or a command alias, described below. +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\.$ + Note that go generate does not parse the file, so lines that look like directives in comments or multiline strings will be treated as directives. -- 2.50.0