Update Documentation on Code Change
A skill for keeping documentation synchronized with code changes. Automatically detects when README.md, API documentation, configuration guides, and other documentation files need updates based on code modifications.
When to Use This Skill
- - Adding new features or functionality
- Changing API endpoints, methods, or interfaces
- Introducing breaking changes
- Modifying dependencies or requirements
- Changing configuration options or environment variables
- Updating installation or setup procedures
- Modifying CLI commands or scripts
- When code examples in documentation become outdated
Prerequisites
- - Understanding of the project's documentation structure
- Access to code changes being made
- Knowledge of documentation files that may need updates
Documentation Update Workflows
README.md Updates
Update README.md when:
- 1. Adding new features or capabilities
- Add feature description to "Features" section
- Include usage examples if applicable
- Update table of contents if present
- 2. Modifying installation or setup process
- Update "Installation" or "Getting Started" section
- Revise dependency requirements
- Update prerequisite lists
- 3. Adding new CLI commands or options
- Document command syntax and examples
- Include option descriptions and default values
- Add usage examples
- 4. Changing configuration options
- Update configuration examples
- Document new environment variables
- Update config file templates
API Documentation Updates
Sync API documentation when:
- 1. New endpoints are added
- Document HTTP method, path, parameters
- Include request/response examples
- Update OpenAPI/Swagger specs
- 2. Endpoint signatures change
- Update parameter lists
- Revise response schemas
- Document breaking changes
- 3. Authentication or authorization changes
- Update authentication examples
- Revise security requirements
- Update API key/token documentation
Code Example Synchronization
Verify and update code examples when:
- 1. Function signatures change
- Update all code snippets using the function
- Verify examples still compile/run
- Update import statements if needed
- 2. API interfaces change
- Update example requests and responses
- Revise client code examples
- Update SDK usage examples
Changelog Management
Add changelog entries for:
- - New features (under "Added" section)
- Bug fixes (under "Fixed" section)
- Breaking changes (under "Changed" section with BREAKING prefix)
- Deprecated features (under "Deprecated" section)
- Removed features (under "Removed" section)
- Security fixes (under "Security" section)
Changelog format:
CODEBLOCK0
Migration Guides
Create migration guides when:
- 1. Breaking API changes occur
- Document what changed
- Provide before/after examples
- Include step-by-step migration instructions
- 2. Major version updates
- List all breaking changes
- Provide upgrade checklist
- Include common migration issues and solutions
- 3. Deprecating features
- Mark deprecated features clearly
- Suggest alternative approaches
- Include timeline for removal
Documentation File Structure
Maintain these documentation files and update as needed:
- - README.md: Project overview, quick start, basic usage
- CHANGELOG.md: Version history and user-facing changes
- docs/: Detailed documentation
-
installation.md: Setup and installation guide
-
configuration.md: Configuration options and examples
-
api.md: API reference documentation
-
contributing.md: Contribution guidelines
-
migration-guides/: Version migration guides
- - examples/: Working code examples and tutorials
Documentation Quality Standards
Writing Guidelines
- - Use clear, concise language
- Include working code examples
- Provide both basic and advanced examples
- Use consistent terminology
- Include error handling examples
- Document edge cases and limitations
Code Example Format
CODEBLOCK1
API Documentation Format
CODEBLOCK2
Best Practices
Do's
- - Update documentation in the same commit as code changes
- Include before/after examples for changes to be reviewed
- Test code examples before committing
- Use consistent formatting and terminology
- Document limitations and edge cases
- Provide migration paths for breaking changes
- Keep documentation DRY (link instead of duplicating)
Don'ts
- - Commit code changes without updating documentation
- Leave outdated examples in documentation
- Document features that don't exist yet
- Use vague or ambiguous language
- Forget to update changelog
- Ignore broken links or failing examples
- Document implementation details users don't need
Validation Commands
Example scripts for documentation validation:
CODEBLOCK3
Review Checklist
Before completing documentation updates:
- - [ ] README.md reflects current project state
- [ ] All new features are documented
- [ ] Code examples are tested and work
- [ ] API documentation is complete and accurate
- [ ] Configuration examples are up to date
- [ ] Breaking changes are documented with migration guide
- [ ] CHANGELOG.md is updated
- [ ] Links are valid and not broken
- [ ] Installation instructions are current
- [ ] Environment variables are documented
Troubleshooting
| Issue | Solution |
|---|
| Outdated code examples | Re-run examples against current code and update |
| Missing API documentation |
Review all public interfaces and document each |
| Broken links | Use link checker tools to identify and fix |
| Inconsistent terminology | Create a glossary and standardize usage |
| Missing changelog entry | Add entry following the changelog format |
代码变更时更新文档
一项用于保持文档与代码变更同步的技能。当README.md、API文档、配置指南及其他文档文件需要根据代码修改进行更新时,自动检测。
何时使用此技能
- - 添加新功能或特性
- 更改API端点、方法或接口
- 引入破坏性变更
- 修改依赖项或需求
- 更改配置选项或环境变量
- 更新安装或设置流程
- 修改CLI命令或脚本
- 文档中的代码示例过时时
前提条件
- - 了解项目的文档结构
- 能够访问正在进行的代码变更
- 知道可能需要更新的文档文件
文档更新工作流程
README.md更新
在以下情况下更新README.md:
- 1. 添加新功能或能力
- 在功能部分添加功能描述
- 如适用,包含使用示例
- 如有目录,更新目录
- 2. 修改安装或设置过程
- 更新安装或入门部分
- 修订依赖项要求
- 更新前提条件列表
- 3. 添加新的CLI命令或选项
- 记录命令语法和示例
- 包含选项描述和默认值
- 添加使用示例
- 4. 更改配置选项
- 更新配置示例
- 记录新的环境变量
- 更新配置文件模板
API文档更新
在以下情况下同步API文档:
- 1. 添加新端点
- 记录HTTP方法、路径、参数
- 包含请求/响应示例
- 更新OpenAPI/Swagger规范
- 2. 端点签名变更
- 更新参数列表
- 修订响应模式
- 记录破坏性变更
- 3. 身份验证或授权变更
- 更新身份验证示例
- 修订安全要求
- 更新API密钥/令牌文档
代码示例同步
在以下情况下验证并更新代码示例:
- 1. 函数签名变更
- 更新所有使用该函数的代码片段
- 验证示例仍能编译/运行
- 如有需要,更新导入语句
- 2. API接口变更
- 更新示例请求和响应
- 修订客户端代码示例
- 更新SDK使用示例
变更日志管理
为以下内容添加变更日志条目:
- - 新功能(在新增部分下)
- 错误修复(在修复部分下)
- 破坏性变更(在变更部分下,带BREAKING前缀)
- 弃用功能(在弃用部分下)
- 移除功能(在移除部分下)
- 安全修复(在安全部分下)
变更日志格式:
markdown
[版本] - 年-月-日
新增
变更
修复
迁移指南
在以下情况下创建迁移指南:
- 1. 发生破坏性API变更
- 记录变更内容
- 提供前后对比示例
- 包含逐步迁移说明
- 2. 主要版本更新
- 列出所有破坏性变更
- 提供升级检查清单
- 包含常见迁移问题和解决方案
- 3. 弃用功能
- 清晰标记弃用功能
- 建议替代方案
- 包含移除时间线
文档文件结构
维护这些文档文件并根据需要更新:
- - README.md:项目概述、快速入门、基本用法
- CHANGELOG.md:版本历史和面向用户的变更
- docs/:详细文档
- installation.md:设置和安装指南
- configuration.md:配置选项和示例
- api.md:API参考文档
- contributing.md:贡献指南
- migration-guides/:版本迁移指南
文档质量标准
编写指南
- - 使用清晰简洁的语言
- 包含可运行的代码示例
- 提供基础示例和高级示例
- 使用一致的术语
- 包含错误处理示例
- 记录边界情况和限制
代码示例格式
markdown
示例:[示例演示内容的清晰描述]
\\\语言
// 包含必要的导入/设置
import { function } from package;
// 完整、可运行的示例
const result = function(parameter);
console.log(result);
\\\
输出:
\\\
预期输出
\\\
API文档格式
markdown
functionName(param1, param2)
函数功能的简要描述。
参数:
- - param1(类型):参数描述
- param2(类型,可选):带默认值的描述
返回:
示例:
\\\语言
const result = functionName(value, 42);
\\\
抛出:
最佳实践
应做事项
- - 在提交代码变更的同一提交中更新文档
- 包含变更前后的示例以供审查
- 在提交前测试代码示例
- 使用一致的格式和术语
- 记录限制和边界情况
- 为破坏性变更提供迁移路径
- 保持文档DRY(链接而非重复)
不应做事项
- - 提交代码变更而不更新文档
- 在文档中保留过时的示例
- 记录尚不存在的功能
- 使用模糊或含糊的语言
- 忘记更新变更日志
- 忽略损坏的链接或失败的示例
- 记录用户不需要的实现细节
验证命令
文档验证的示例脚本:
json
{
scripts: {
docs:build: 构建文档,
docs:test: 测试文档中的代码示例,
docs:lint: 检查文档文件格式,
docs:links: 检查损坏的链接,
docs:spell: 拼写检查文档,
docs:validate: 运行所有文档检查
}
}
审查清单
在完成文档更新之前:
- - [ ] README.md反映当前项目状态
- [ ] 所有新功能都已记录
- [ ] 代码示例已测试并正常工作
- [ ] API文档完整且准确
- [ ] 配置示例是最新的
- [ ] 破坏性变更已记录并附迁移指南
- [ ] CHANGELOG.md已更新
- [ ] 链接有效且未损坏
- [ ] 安装说明是最新的
- [ ] 环境变量已记录
故障排除
| 问题 | 解决方案 |
|---|
| 过时的代码示例 | 针对当前代码重新运行示例并更新 |
| 缺少API文档 |
审查所有公共接口并逐一记录 |
| 损坏的链接 | 使用链接检查工具识别并修复 |
| 不一致的术语 | 创建术语表并标准化使用 |
| 缺少变更日志条目 | 按照变更日志格式添加条目 |