@@ -498,25 +498,6 @@ are written in source code but will adjust presentation to make
498498the semantic meaning of a particular comment clearer,
499499analogous to reformatting ` 1+2 * 3 ` to ` 1 + 2*3 ` in ordinary source code.
500500
501- Directive comments such as ` //go:generate ` are not
502- considered part of a doc comment and are omitted from
503- rendered documentation.
504- Gofmt moves directive comments to the end of the doc comment,
505- preceded by a blank line.
506- For example:
507-
508- package regexp
509-
510- // An Op is a single regular expression operator.
511- //
512- //go:generate stringer -type Op -trimprefix Op
513- type Op uint8
514-
515- A directive comment is a line matching the regular expression
516- ` //(line |extern |export |[a-z0-9]+:[a-z0-9]) ` .
517- Tools that define their own directives should use the form
518- ` //toolname:directive ` .
519-
520501Gofmt removes leading and trailing blank lines in doc comments.
521502If all lines in a doc comment begin with the same sequence of
522503spaces and tabs, gofmt removes that prefix.
@@ -871,6 +852,40 @@ replacing any other indentation the non-blank lines have in common.
871852Gofmt also inserts a blank line before and after each code block,
872853distinguishing the code block clearly from the surrounding paragraph text.
873854
855+ ### Directives {#directives}
856+
857+ Directive comments such as ` //go:generate ` are not
858+ considered part of a doc comment and are omitted from
859+ rendered documentation.
860+ Gofmt moves directive comments to the end of the doc comment,
861+ preceded by a blank line.
862+ For example:
863+
864+ package regexp
865+
866+ // An Op is a single regular expression operator.
867+ //
868+ //go:generate stringer -type Op -trimprefix Op
869+ type Op uint8
870+
871+ A directive comment is a line starting with the regular expression
872+ ` //(line |extern |export |[a-z0-9]+:[a-z0-9]) ` .
873+
874+ Tools may define their own directive comments using the form
875+ ` //toolname:directive arguments ` .
876+ Tool directives match the regular expression
877+ ` //([a-z0-9]+):([a-z0-9]\PZ*)($|\pZ+)(.*) ` , where the first group
878+ is the tool name and the second group is the directive name.
879+ Optional arguments are separated from the directive name by
880+ one or more Unicode whitespace characters.
881+ Each tool may define its own argument syntax, but a common convention is a
882+ sequence of space-separated arguments, where an argument may be
883+ a bare word, or a double-quoted or backtick-quoted Go string.
884+ The tool name ` go ` is reserved for use by the Go toolchain.
885+
886+ The [ ` go/ast.ParseDirective ` ] ( /pkg/go/ast#ParseDirective ) function and its
887+ related types parse the tool directive syntax.
888+
874889## Common mistakes and pitfalls {#mistakes}
875890
876891The rule that any span of indented or blank lines
0 commit comments