Code Formatting Skill
This skill provides code formatting operations for the project codebase, which is a Rust workspace.
When to Use This Skill
Use this skill when you need to:
- Format code after editing Rust files
- Check if code meets formatting standards
- Ensure code formatting compliance before commits
Command Selection Rules
Choose the appropriate command based on the number of crates/files edited:
| Scenario | Command | Rationale |
|---|---|---|
| 1 crate, 1-2 files | just fmt-file <file> (per file) |
Faster, targeted formatting |
| 1 crate, 3+ files | just fmt |
More efficient than multiple per-file calls |
| 2+ crates | just fmt |
Always use workspace-wide formatting |
Decision process:
- Identify how many crates contain your edited files
- If 2 or more crates: use
just fmt - If exactly 1 crate with 1-2 files: use
just fmt-filefor each file - If exactly 1 crate with 3+ files: use
just fmt
Available Commands
Format Rust Code
just fmt
Formats all Rust code using cargo +nightly fmt --all. This is the primary formatting command.
Check Rust Formatting
just fmt-check
Checks Rust code formatting without making changes using cargo +nightly fmt --all -- --check.
Format Specific File
just fmt-file <FILE>
Formats a specific Rust file.
Examples:
just fmt-file src/main.rs- formats a Rust file
Important Guidelines
Format Before Checks/Commit
Format code when you finish a coherent chunk of work and before running checks or committing.
This is a critical requirement from the project's development workflow:
- Do not skip formatting before checks/commit
- Use the Command Selection Rules above to choose the right command
- Run formatting before any check or test commands
Example Workflows
Single file edit:
- Edit a Rust file:
src/common/utils.rs - When ready to validate, run:
just fmt-file src/common/utils.rs - Then run checks
Multiple files edit (3+):
- Edit multiple Rust files across the codebase
- When ready to validate, run:
just fmt - Then run checks
Common Mistakes to Avoid
❌ Anti-patterns
- Never run
cargo fmtdirectly - Usejust fmt-fileorjust fmt - Never run
rustfmtdirectly - The justfile includes proper flags - Never skip formatting before checks/commit - Even "minor" edits need formatting
- Never use
just fmtfor 1-2 files in a single crate - Usejust fmt-file <file>for efficiency - Never use
just fmt-filefor 2+ crates or 3+ files - Usejust fmtfor efficiency
✅ Best Practices
- Format before running checks/tests or before committing
- Use
just fmt-filefor 1-2 files within a single crate (faster, targeted) - Use
just fmtfor 2+ crates or 3+ files (more efficient) - Run
just fmt-checkto verify formatting before commits
Next Steps
After formatting your code:
- Check compilation → See
.claude/skills/code-check/SKILL.md - Run clippy → See
.claude/skills/code-check/SKILL.md - Run targeted tests when warranted → See
.claude/skills/code-test/SKILL.md