Go Doc Comments
БесплатноБез исполняемых скриптовНе проверенWrites and supplements Go source comments to the official Go doc comment standard (go.dev/doc/comment). Use when adding, fixing, or reviewing comments in .go…
от rroy233305 установок в других каталогахОб этом скилле
go-doc-comments
Guidance for writing and supplementing Go comments so they are idiomatic, tool-friendly, and conform to go.dev/doc/comment.
Core Principle
Write code that speaks for itself. In Go, that means clear names and structure for the WHAT, and doc comments that add WHY, contracts, and context.
Two rules pull in different directions — hold both:
- Comment sparingly inside function bodies. Most implementation code needs no comments; good naming beats a comment. Explain WHY (design decisions, non-obvious trade-offs, workarounds), not WHAT.
- But document every exported identifier. This is a hard Go convention, not a preference. Every exported (capitalized) package, func, type, const, and var should have a doc comment.
go doc,gopls, andpkg.go.devextract these. A missing doc comment on an exported symbol is a defect, even when the symbol looks obvious.
The distinction: rule 1 governs comments inside bodies; rule 2 governs doc comments on declarations. Do not conflate them — "self-documenting code" is never a reason to skip a doc comment on an exported API.
Decision Framework
Run this before writing any comment. It decides both whether to comment and what kind.
Step 0 — Is this an exported declaration?
- YES → a doc comment is mandatory (rule 2). Skip the rest of this framework; go to Doc Comment Conventions. "The name is obvious" does not exempt exported API.
- NO (unexported symbol, or a line inside a function body) → continue to Step 1. This is where "comment sparingly" applies.
Step 1 — Is the code self-explanatory?
- YES → no comment. Stop.
- NO → Step 2.
Step 2 — Would a better name or a small refactor remove the need?
- YES → refactor instead of commenting. Rename the variable, or extract the tangled expression into a well-named function. Prefer this over a clarifying comment.
- NO → Step 3.
Step 3 — Does the comment explain WHY, not WHAT?
- Explaining WHAT the code does → the code should say that itself; go back to Step 2 and make it clearer.
- Explaining WHY (rationale, constraint, workaround, gotcha, non-obvious algorithm choice, performance bound) → this is a good comment. Write it.
Refactor over comment — example
// BAD: comment compensates for an unclear condition
// grant access to admins and users with the special flag
if u.role == "admin" || (u.perms != nil && u.perms["special"]) {
// GOOD: the condition names itself; no comment needed
if userHasAdminAccess(u) {
Language of Comments
Detect the existing comment language in the file/package and match it. If existing comments are in Chinese, write new comments in Chinese; if English, use English. When a file or package has no existing comments, default to English.
Regardless of prose language, keep Go's structural idioms in their canonical form:
- The identifier-first sentence still starts with the symbol name (e.g.
// Quote 返回 s 的双引号 Go 字符串字面量。— the leading token isQuote, not a translated name). Deprecated:markers,TODO(user):/BUG(user):notes, and doc-link syntax[pkg.Name]stay in their standard form.Deprecated:is a recognized machine token — never translate it.- Package comments still begin with
Package <name>(or the command name forpackage main).
Placement Rules (non-negotiable)
- A doc comment sits immediately before its declaration with no blank line between comment and declaration. A blank line demotes it to an ordinary comment that tools ignore.
- Use
//line comments./* */is allowed (common for long package comments) but//is idiomatic for most doc comments. - The package comment appears in exactly one file of a multi-file package.
Doc Comment Conventions by Declaration
Package
Begins with Package <name>; for a command (package main), begins with the capitalized program name describing behavior.
// Package path implements utility routines for manipulating slash-separated
// paths.
//
// The path package should only be used for paths separated by forward
// slashes; to manipulate operating system paths, use [path/filepath].
package path
Functions and methods
Start with the function name. State what it returns, or for side-effect functions what it does.
- Boolean-returning functions: use "reports whether", and omit "or not".
// HasPrefix reports whether the string s begins with prefix. func HasPrefix(s, prefix string) bool - Refer to parameters and results by their names directly (no special syntax).
- Name results in the comment when it aids clarity; document special cases and error contracts.
// Copy copies from src to dst until either EOF is reached // on src or an error occurs. It returns the total number of bytes // written and the first error encountered while copying, if
Установить Go Doc Comments в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Go Doc Comments?
Writes and supplements Go source comments to the official Go doc comment standard (go.dev/doc/comment). Use when adding, fixing, or reviewing comments in .go files — package comments, doc comments for exported functions/types/constants/variables, godoc/pkg.go.dev documentation, or when discussing Go commenting conventions. Covers the decision of whether to comment at all, identifier-first sentences, doc-link syntax, gofmt-safe formatting, and matching the existing comment language.
Как установить скилл Go Doc Comments?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Go Doc Comments запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic