Code Commenter Skill
This skill specializes in adding meaningful, high-quality comments to source code, with specific language rules for production vs. test code.
Goals
- •Documentation: Ensure core and main methods have proper documentation.
- •Clarification: Add inline comments to explain complex logic in core methods.
- •Test Context: clearly explain test scenarios and verification steps.
Guidelines
1. Production Code (Core & Main Methods) -> ENGLISH
- •Target: ONLY add comments to Core Methods (critical logic, interfaces, complex algorithms) and Main Methods (entry points, public APIs).
- •Language: ENGLISH ONLY.
- •Style:
- •Exported methods: GoDoc style (e.g.,
// FunctionName does X...). - •Complex logic: Concise inline English explanations.
- •Exported methods: GoDoc style (e.g.,
- •Skip: Trivial getters/setters, simple logic, or boilerplate.
2. Test Code (Test Cases) -> CHINESE
- •Target: Every added or modified test case/function.
- •Language: CHINESE ONLY.
- •Content:
- •Explain the Scenario (测试场景).
- •Explain the Verification Logic (验证逻辑).
- •Explain any Mock Data purpose (模拟数据用途).
- •Example:
go
// TestUserLogin_Success 测试用户成功登录的场景 // 步骤: // 1. 模拟数据库返回有效用户 // 2. 调用 Login 方法 // 3. 验证返回的 Token 不为空 func TestUserLogin_Success(t *testing.T) { ... }
3. General Rules
- •No Logic Changes: strictly ONLY add comments. Do not modify the code structure or logic.
- •Conciseness: Avoid redundant comments (e.g.,
i++ // increment i).
Process
- •Identify Type: Is this Production Code or Test Code?
- •Select Language: English for Production (Core/Main), Chinese for Tests.
- •Filter: For Production, only target Core/Main methods. For Tests, target all modified cases.
- •Apply: Insert comments.
Example Interaction
User: "Add comments to this PR." Agent:
- •Finds
core/user.go: Adds English comments toLoginandRegister(Core methods). - •Finds
core/user_test.go: Adds Chinese comments toTestLoginexplaining the test steps.