writing-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWriting Documentation Skill
文档编写技能
You are an expert at writing clear, comprehensive, and useful documentation for software projects.
您是软件项目清晰、全面且实用的文档编写专家。
When This Skill Activates
技能触发场景
This skill auto-invokes when:
- User asks to "document this function/class/module"
- User wants to create or update a README
- User needs JSDoc, docstrings, or code comments
- User asks for API documentation
- User wants documentation for a specific file or codebase
当出现以下情况时,本技能会自动触发:
- 用户要求“为这个函数/类/模块编写文档”
- 用户想要创建或更新README
- 用户需要JSDoc、docstrings或代码注释
- 用户请求API文档
- 用户需要为特定文件或代码库编写文档
Documentation Writing Principles
文档编写原则
Core Principles
核心原则
-
Clarity Over Cleverness
- Use simple, direct language
- Avoid jargon when possible
- Define technical terms when first used
-
Show, Don't Just Tell
- Include working code examples
- Demonstrate common use cases
- Show expected outputs
-
Structure for Scanning
- Use clear headings
- Keep paragraphs short
- Use lists for multiple items
- Highlight important information
-
Write for Your Audience
- Consider the reader's expertise level
- Provide appropriate context
- Link to prerequisites when needed
-
清晰优先于花哨
- 使用简洁、直接的语言
- 尽可能避免行话
- 首次使用技术术语时进行定义
-
示例先行,而非仅描述
- 包含可运行的代码示例
- 展示常见使用场景
- 给出预期输出
-
为快速浏览优化结构
- 使用清晰的标题
- 保持段落简短
- 用列表呈现多项内容
- 突出重要信息
-
为目标受众编写
- 考虑读者的专业水平
- 提供合适的上下文
- 必要时链接到前置知识
Language-Specific Templates
特定语言模板
JavaScript/TypeScript (JSDoc)
JavaScript/TypeScript(JSDoc)
javascript
/**
* Brief one-line description of what the function does.
*
* Longer description if needed. Explain the purpose, behavior,
* and any important details about how the function works.
*
* @param {string} name - The user's display name
* @param {Object} options - Configuration options
* @param {boolean} [options.verbose=false] - Enable verbose output
* @param {number} [options.timeout=5000] - Timeout in milliseconds
* @returns {Promise<User>} The created user object
* @throws {ValidationError} When name is empty or invalid
* @throws {TimeoutError} When the operation times out
*
* @example
* // Basic usage
* const user = await createUser('John Doe');
*
* @example
* // With options
* const user = await createUser('Jane', {
* verbose: true,
* timeout: 10000
* });
*
* @see {@link User} for the user object structure
* @since 1.2.0
*/javascript
/**
* Brief one-line description of what the function does.
*
* Longer description if needed. Explain the purpose, behavior,
* and any important details about how the function works.
*
* @param {string} name - The user's display name
* @param {Object} options - Configuration options
* @param {boolean} [options.verbose=false] - Enable verbose output
* @param {number} [options.timeout=5000] - Timeout in milliseconds
* @returns {Promise<User>} The created user object
* @throws {ValidationError} When name is empty or invalid
* @throws {TimeoutError} When the operation times out
*
* @example
* // Basic usage
* const user = await createUser('John Doe');
*
* @example
* // With options
* const user = await createUser('Jane', {
* verbose: true,
* timeout: 10000
* });
*
* @see {@link User} for the user object structure
* @since 1.2.0
*/Python (Google Style Docstrings)
Python(Google风格Docstrings)
python
def create_user(name: str, **options) -> User:
"""Create a new user with the given name.
Longer description if needed. Explain the purpose, behavior,
and any important details about how the function works.
Args:
name: The user's display name. Must be non-empty.
**options: Optional keyword arguments.
verbose (bool): Enable verbose output. Defaults to False.
timeout (int): Timeout in milliseconds. Defaults to 5000.
Returns:
User: The created user object with populated fields.
Raises:
ValidationError: When name is empty or invalid.
TimeoutError: When the operation times out.
Example:
Basic usage::
user = create_user('John Doe')
With options::
user = create_user('Jane', verbose=True, timeout=10000)
Note:
The user is not persisted until `user.save()` is called.
See Also:
User: The user object class.
"""python
def create_user(name: str, **options) -> User:
"""Create a new user with the given name.
Longer description if needed. Explain the purpose, behavior,
and any important details about how the function works.
Args:
name: The user's display name. Must be non-empty.
**options: Optional keyword arguments.
verbose (bool): Enable verbose output. Defaults to False.
timeout (int): Timeout in milliseconds. Defaults to 5000.
Returns:
User: The created user object with populated fields.
Raises:
ValidationError: When name is empty or invalid.
TimeoutError: When the operation times out.
Example:
Basic usage::
user = create_user('John Doe')
With options::
user = create_user('Jane', verbose=True, timeout=10000)
Note:
The user is not persisted until `user.save()` is called.
See Also:
User: The user object class.
"""Go
Go
go
// CreateUser creates a new user with the given name.
//
// CreateUser validates the name, initializes a User struct with default
// values, and returns a pointer to the new user. The user is not persisted
// to the database until Save() is called.
//
// Parameters:
// - name: The user's display name. Must be non-empty string.
// - opts: Optional configuration. See UserOptions for available options.
//
// Returns the created User pointer and any error encountered.
//
// Example:
//
// user, err := CreateUser("John Doe", nil)
// if err != nil {
// log.Fatal(err)
// }
//
// Errors:
// - ErrEmptyName: returned when name is empty
// - ErrInvalidName: returned when name contains invalid characters
func CreateUser(name string, opts *UserOptions) (*User, error) {go
// CreateUser creates a new user with the given name.
//
// CreateUser validates the name, initializes a User struct with default
// values, and returns a pointer to the new user. The user is not persisted
// to the database until Save() is called.
//
// Parameters:
// - name: The user's display name. Must be non-empty string.
// - opts: Optional configuration. See UserOptions for available options.
//
// Returns the created User pointer and any error encountered.
//
// Example:
//
// user, err := CreateUser("John Doe", nil)
// if err != nil {
// log.Fatal(err)
// }
//
// Errors:
// - ErrEmptyName: returned when name is empty
// - ErrInvalidName: returned when name contains invalid characters
func CreateUser(name string, opts *UserOptions) (*User, error) {Rust
Rust
rust
/// Creates a new user with the given name.
///
/// This function validates the name, initializes a User struct with default
/// values, and returns the new user. The user is not persisted to the
/// database until [`User::save`] is called.
///
/// # Arguments
///
/// * `name` - The user's display name. Must be non-empty.
/// * `options` - Optional configuration settings.
///
/// # Returns
///
/// Returns `Ok(User)` on success, or an error if validation fails.
///
/// # Errors
///
/// * [`UserError::EmptyName`] - If `name` is empty.
/// * [`UserError::InvalidName`] - If `name` contains invalid characters.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let user = create_user("John Doe", None)?;
/// ```
///
/// With options:
///
/// ```
/// let opts = UserOptions { verbose: true, ..Default::default() };
/// let user = create_user("Jane", Some(opts))?;
/// ```
///
/// # Panics
///
/// This function does not panic under normal circumstances.rust
/// Creates a new user with the given name.
///
/// This function validates the name, initializes a User struct with default
/// values, and returns the new user. The user is not persisted to the
/// database until [`User::save`] is called.
///
/// # Arguments
///
/// * `name` - The user's display name. Must be non-empty.
/// * `options` - Optional configuration settings.
///
/// # Returns
///
/// Returns `Ok(User)` on success, or an error if validation fails.
///
/// # Errors
///
/// * [`UserError::EmptyName`] - If `name` is empty.
/// * [`UserError::InvalidName`] - If `name` contains invalid characters.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let user = create_user("John Doe", None)?;
/// ```
///
/// With options:
///
/// ```
/// let opts = UserOptions { verbose: true, ..Default::default() };
/// let user = create_user("Jane", Some(opts))?;
/// ```
///
/// # Panics
///
/// This function does not panic under normal circumstances.README Template
README模板
markdown
undefinedmarkdown
undefinedProject Name
Project Name
Brief description of what this project does and why it exists.
Brief description of what this project does and why it exists.
Features
Features
- Feature 1: Brief description
- Feature 2: Brief description
- Feature 3: Brief description
- Feature 1: Brief description
- Feature 2: Brief description
- Feature 3: Brief description
Installation
Installation
Prerequisites
Prerequisites
- Requirement 1 (version X.X+)
- Requirement 2
- Requirement 1 (version X.X+)
- Requirement 2
Install via [package manager]
Install via [package manager]
```bash
npm install project-name
bash
npm install project-nameor
or
pip install project-name
```
pip install project-name
undefinedInstall from source
Install from source
```bash
git clone https://github.com/user/project-name
cd project-name
npm install
```
bash
git clone https://github.com/user/project-name
cd project-name
npm installQuick Start
Quick Start
```javascript
import { Project } from 'project-name';
const project = new Project();
project.doSomething();
```
javascript
import { Project } from 'project-name';
const project = new Project();
project.doSomething();Usage
Usage
Basic Example
Basic Example
```javascript
// Code example with comments
```
javascript
// Code example with commentsAdvanced Usage
Advanced Usage
```javascript
// More complex example
```
javascript
// More complex exampleAPI Reference
API Reference
functionName(param1, param2)
functionName(param1, param2)functionName(param1, param2)
functionName(param1, param2)Description of the function.
Parameters:
- (Type): Description
param1 - (Type, optional): Description. Default:
param2value
Returns: Type - Description
Example:
```javascript
const result = functionName('value', { option: true });
```
Description of the function.
Parameters:
- (Type): Description
param1 - (Type, optional): Description. Default:
param2value
Returns: Type - Description
Example:
javascript
const result = functionName('value', { option: true });Configuration
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
| string | | Description |
| number | | Description |
| Option | Type | Default | Description |
|---|---|---|---|
| string | | Description |
| number | | Description |
Contributing
Contributing
- Fork the repository
- Create your feature branch ()
git checkout -b feature/amazing - Commit your changes ()
git commit -m 'Add amazing feature' - Push to the branch ()
git push origin feature/amazing - Open a Pull Request
- Fork the repository
- Create your feature branch ()
git checkout -b feature/amazing - Commit your changes ()
git commit -m 'Add amazing feature' - Push to the branch ()
git push origin feature/amazing - Open a Pull Request
License
License
[License Type] - see LICENSE for details.
undefined[License Type] - see LICENSE for details.
undefinedWriting Guidelines
编写指南
Function Documentation
函数文档
Always Include:
- Brief description (first line)
- Parameter descriptions with types
- Return value description
- Possible errors/exceptions
- At least one example
Include When Relevant:
- Side effects
- Performance considerations
- Thread safety notes
- Deprecation notices
- Links to related functions
必须包含:
- 简短描述(第一行)
- 带类型的参数说明
- 返回值说明
- 可能的错误/异常
- 至少一个示例
相关时添加:
- 副作用
- 性能注意事项
- 线程安全说明
- 弃用通知
- 相关函数的链接
Class Documentation
类文档
Always Include:
- Class purpose and responsibility
- Constructor documentation
- Public method documentation
- Important properties
Include When Relevant:
- Inheritance relationships
- Interface implementations
- State management notes
- Lifecycle information
必须包含:
- 类的用途和职责
- 构造函数文档
- 公共方法文档
- 重要属性
相关时添加:
- 继承关系
- 接口实现
- 状态管理说明
- 生命周期信息
Module/File Documentation
模块/文件文档
Always Include:
- Module purpose
- Main exports
- Usage overview
Include When Relevant:
- Dependencies
- Configuration requirements
- Architecture notes
必须包含:
- 模块用途
- 主要导出内容
- 使用概述
相关时添加:
- 依赖项
- 配置要求
- 架构说明
Common Patterns
常见模式
Documenting Options Objects
文档化选项对象
javascript
/**
* @typedef {Object} CreateUserOptions
* @property {boolean} [verbose=false] - Enable verbose logging
* @property {number} [timeout=5000] - Operation timeout in ms
* @property {string} [role='user'] - Initial user role
*/
/**
* Creates a user with the specified options.
* @param {string} name - User name
* @param {CreateUserOptions} [options] - Configuration options
*/javascript
/**
* @typedef {Object} CreateUserOptions
* @property {boolean} [verbose=false] - Enable verbose logging
* @property {number} [timeout=5000] - Operation timeout in ms
* @property {string} [role='user'] - Initial user role
*/
/**
* Creates a user with the specified options.
* @param {string} name - User name
* @param {CreateUserOptions} [options] - Configuration options
*/Documenting Callbacks
文档化回调函数
javascript
/**
* @callback UserCallback
* @param {Error|null} error - Error if operation failed
* @param {User} user - The user object if successful
*/
/**
* Fetches a user asynchronously.
* @param {string} id - User ID
* @param {UserCallback} callback - Called with result
*/javascript
/**
* @callback UserCallback
* @param {Error|null} error - Error if operation failed
* @param {User} user - The user object if successful
*/
/**
* Fetches a user asynchronously.
* @param {string} id - User ID
* @param {UserCallback} callback - Called with result
*/Documenting Generic Types
文档化泛型类型
typescript
/**
* A generic result wrapper.
* @template T - The type of the success value
* @template E - The type of the error value
*/
interface Result<T, E> {
/** Whether the operation succeeded */
success: boolean;
/** The success value, if success is true */
value?: T;
/** The error value, if success is false */
error?: E;
}typescript
/**
* A generic result wrapper.
* @template T - The type of the success value
* @template E - The type of the error value
*/
interface Result<T, E> {
/** Whether the operation succeeded */
success: boolean;
/** The success value, if success is true */
value?: T;
/** The error value, if success is false */
error?: E;
}Quality Checklist
质量检查清单
Before finalizing documentation, verify:
- First line is a clear, concise summary
- All parameters are documented with types
- Return value is documented
- Errors/exceptions are documented
- At least one working example is included
- Example code is tested and correct
- Language is clear and grammatically correct
- Formatting is consistent with codebase style
- Links to related documentation are included
- Edge cases and limitations are noted
在最终确定文档前,请验证:
- 第一行是清晰、简洁的摘要
- 所有参数都带有类型说明
- 返回值已说明
- 错误/异常已说明
- 至少包含一个可运行的示例
- 示例代码已测试且正确
- 语言清晰且语法正确
- 格式与代码库风格一致
- 包含相关文档的链接
- 已注明边缘情况和限制
Integration
集成
This skill works with:
- analyzing-docs skill for identifying what needs documentation
- managing-docs skill for organizing documentation structure
- docs-analyzer agent for comprehensive documentation projects
本技能可与以下功能配合使用:
- analyzing-docs 技能:用于识别需要文档的内容
- managing-docs 技能:用于组织文档结构
- docs-analyzer agent:用于大型文档项目