Code Documentation

aj-geddes/useful-ai-prompts/skills/code-documentation

作者 aj-geddes3f5182cfd739無授權條款355 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫7 個月前更新

Write comprehensive code documentation including JSDoc, Python docstrings, inline comments, function documentation, and API comments. Use when documenting code, writing docstrings, or creating inline documentation.

AI 產生的概覽

撰寫程式碼文件,例如 JSDoc、Python docstring、JavaDoc 與行內註解。

功能
此技能引導代理撰寫程式碼文件:函式與類別文件、型別定義、模組文件、API 註解與行內註解。它提供 JSDoc、Python docstring、JavaDoc 等語言特定慣例,並附有快速入門範例與最佳實務的正反清單。技能另含參考指南與文件範本作為輔助素材。
適用情境
適用於為程式碼撰寫文件、撰寫 docstring 或加入行內註解的情境。適合涵蓋公開 API、參數、回傳值、拋出的例外、使用範例與型別定義等任務。
執行需求
不需腳本,僅有指示、參考指南與範本。代理只需讀取隨附的 markdown 檔案。

Code Documentation

Table of Contents

Overview

Create clear, comprehensive code documentation using language-specific standards like JSDoc, Python docstrings, JavaDoc, and inline comments.

When to Use

  • Function and class documentation
  • JSDoc for JavaScript/TypeScript
  • Python docstrings
  • JavaDoc for Java
  • Inline code comments
  • API documentation from code
  • Type definitions
  • Usage examples in code

Quick Start

Minimal working example:

javascript
/** * Calculates the total price including tax and discount. * * @param {number} basePrice - The base price before tax and discount * @param {number} taxRate - Tax rate as a decimal (e.g., 0.08 for 8%) * @param {number} [discount=0] - Optional discount amount * @returns {number} The final price after tax and discount * @throws {Error} If basePrice or taxRate is negative * * @example * const price = calculateTotalPrice(100, 0.08, 10); * console.log(price); // 98 * * @example * // Without discount * const price = calculateTotalPrice(100, 0.08); * console.log(price); // 108 */function calculateTotalPrice(basePrice, taxRate, discount = 0) {  if (basePrice < 0 || taxRate < 0) {    throw new Error("Price and tax rate must be non-negative");  }  return basePrice * (1 + taxRate) - discount;}
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Function Documentation [blocked]Function Documentation
Class Documentation [blocked]Class Documentation
Type Definitions [blocked]Type Definitions
Function Documentation [blocked]Function Documentation
Class Documentation [blocked]Class Documentation
Module Documentation [blocked]Module Documentation

Best Practices

✅ DO

  • Document public APIs thoroughly
  • Include usage examples
  • Document parameters and return values
  • Specify thrown exceptions/errors
  • Use language-specific standards (JSDoc, docstrings, etc.)
  • Keep comments up-to-date
  • Document "why" not "what"
  • Include edge cases and gotchas
  • Add links to related functions
  • Document type definitions
  • Use consistent formatting

❌ DON'T

  • State the obvious in comments
  • Leave commented-out code
  • Write misleading comments
  • Skip examples for complex functions
  • Use vague parameter descriptions
  • Forget to update docs when code changes
  • Over-comment simple code

來源與署名

來源:aj-geddes/useful-ai-prompts位於skills/code-documentation提交3f5182c

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架