add-feature
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd Feature
添加功能
Guide for adding new functionality to Syncpack.
为Syncpack添加新功能的指南。
Quick Decision
快速决策
What are you adding?
- New CLI command (lint, fix, format, etc.) → See adding-command.md
- New validation logic (InstanceState variant) → See adding-instance-state.md
- Both → Start with instance state, then add command
你要添加的内容是什么?
- 新CLI命令(lint、fix、format等)→ 查看adding-command.md
- 新验证逻辑(InstanceState变体)→ 查看adding-instance-state.md
- 两者都有 → 先从InstanceState开始,再添加命令
Prerequisites
前提条件
Before adding any feature:
- Understand the 3-phase pattern: Create Context → Inspect Context → Run Command
- Know which phase your feature affects
- Check if similar code exists (use )
ast-grep -p 'PATTERN' src/
添加任何功能之前:
- 理解三阶段模式:创建上下文 → 检查上下文 → 运行命令
- 明确你的功能会影响哪个阶段
- 检查是否存在类似代码(使用)
ast-grep -p 'PATTERN' src/
Feature Types
功能类型
Commands
命令
Commands are user-facing operations (, , etc.).
syncpack lintsyncpack fixWhen to create a new command:
- New user-facing operation that doesn't fit existing commands
- Different output format or behaviour needed
Registration points (all three required):
- - Add to
src/cli.rsenumSubcommand - - Add match arm for dispatch
src/main.rs - - Implement
src/commands/*.rspub fn run(ctx: Context) -> i32
→ Full guide: adding-command.md
命令是面向用户的操作(、等)。
syncpack lintsyncpack fix何时创建新命令:
- 新的面向用户操作,不适合现有命令
- 需要不同的输出格式或行为
注册点(三个都需要):
- - 添加到
src/cli.rs枚举Subcommand - - 添加用于分发的匹配分支
src/main.rs - - 实现
src/commands/*.rspub fn run(ctx: Context) -> i32
→ 完整指南:adding-command.md
Instance States
InstanceState
InstanceState variants describe validation results (valid, fixable, unfixable, suspect).
When to add a new state:
- New validation rule needed
- New type of error/warning to report
- New auto-fix capability
Location: +
src/instance_state.rssrc/visit_packages/*.rs→ Full guide: adding-instance-state.md
InstanceState变体描述验证结果(有效、可修复、不可修复、可疑)。
何时添加新状态:
- 需要新的验证规则
- 需要报告新类型的错误/警告
- 需要新的自动修复能力
位置: +
src/instance_state.rssrc/visit_packages/*.rs→ 完整指南:adding-instance-state.md
Common Workflow
通用工作流
- Write failing test using TestBuilder
- Implement minimal code to pass
- Run and fix warnings
cargo clippy - Refactor if needed
- Update documentation
- 使用TestBuilder编写失败的测试
- 实现最小化代码以通过测试
- 运行并修复警告
cargo clippy - 如有需要进行重构
- 更新文档
Checklist
检查清单
Before submitting:
- Tests pass ()
just test - Zero clippy warnings
- Follows existing patterns
- Registered in all required places (for commands)
- Uses TDD approach
提交前:
- 测试通过()
just test - 无clippy警告
- 遵循现有模式
- 在所有必要位置注册(针对命令)
- 使用TDD方法