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 从公开仓库中收录这些内容。

举报或申请下架