Skip to content

doc-first-word

Gostyleno fixdefault: offgo/revive

Reports an exported function, method, type, constant or variable whose doc comment does not start with its name. A type may start with A, An, The or This before the name. The comment of a group in parentheses is the comment of its types, and a constant or variable in a group whose comment has text is not checked. Directive lines (//go:generate) and a first line Deprecated: are not text. A declaration with no comment is left to missing-doc-comment.

go doc and the package pages show the first sentence of a comment as the summary of the name, and search and lists read it as “Name does …”. A comment that starts with another word makes that sentence read wrong in the generated documentation.

To fix, start the comment with the name: // Run does things.

Reported
...
func Run() {}
// does it.
func Wrong() {}
...
type U int
// Other
type V int
...
)
// Wrong names a variable.
var E = 1
...
func (T) Method() {}
// does it.
func (T) Other() {}
go:
lint:
rules:
doc-first-word: warn # off (default), warn, error

Enabled by the presets: go/revive.

Suppress one line with sudsy-disable-next-line doc-first-word in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
revive exported partial No stuttering check (a name that starts with the package name), no own-declaration check for var a, B; a method that is sortable through methods in another file of the package is reported