Code Formatting Skill
This skill provides code formatting operations for the project codebase, which is a single-crate Rust workspace with shell scripts.
When to Use This Skill
Use this skill when you need to:
- •Format code after editing Rust or shell script files
- •Format the
installscript after making changes - •Check if code meets formatting standards
- •Ensure code formatting compliance before commits
Command Selection Rules
Choose the appropriate command based on the number of files edited:
| Files Edited | File Type | Command to Use | Rationale |
|---|---|---|---|
| 1-2 files | Rust | just fmt-rs-file <file> (per file) | Faster, targeted formatting |
| 3+ files | Rust | just fmt-rs (global) | More efficient than multiple per-file calls |
| Any | Shell | just fmt-sh | Formats the install script |
Decision process:
- •Count the number of files you edited (by type: Rust or Shell)
- •If 2 or fewer Rust files: run
just fmt-rs-filefor each file - •If 3 or more Rust files: run the global command
just fmt-rs - •For shell scripts: always run
just fmt-sh(currently only formats theinstallscript)
Available Commands
Format Rust Code
just fmt-rs
Formats all Rust code using cargo +nightly fmt --all. This is the primary formatting command.
Alias: just fmt (same as fmt-rs)
Check Rust Formatting
just fmt-rs-check
Checks Rust code formatting without making changes using cargo +nightly fmt --all -- --check.
Alias: just fmt-check (same as fmt-rs-check)
Format Specific Rust File
just fmt-rs-file <FILE>
Formats a specific Rust file using cargo +nightly fmt.
Examples:
- •
just fmt-rs-file ampup/src/main.rs- formats a Rust file - •
just fmt-rs-file ampup/src/config.rs- formats another Rust file
Format Shell Scripts
just fmt-sh
Formats shell scripts. Currently formats the install script.
Requirements: Requires shfmt to be installed. The command will provide installation instructions if not available.
Check Shell Script Formatting
just fmt-sh-check
Checks shell script formatting without making changes.
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:
ampup/src/config.rs - •When ready to validate, run:
just fmt-rs-file ampup/src/config.rs - •Then run checks
Multiple files edit (3+):
- •Edit multiple Rust files across the codebase
- •When ready to validate, run:
just fmt-rs - •Then run checks
Shell script edit:
- •Edit the
installscript - •When ready to validate, run:
just fmt-sh - •Then run checks
Common Mistakes to Avoid
❌ Anti-patterns
- •Never run
cargo fmtdirectly - Usejust fmt-rs-fileorjust fmt-rs - •Never run
rustfmtdirectly - The justfile includes proper flags - •Never run
shfmtdirectly - Usejust fmt-sh - •Never skip formatting before checks/commit - Even "minor" edits need formatting
- •Never use
just fmt-rsfor 1-2 files - Usejust fmt-rs-file <file>for efficiency - •Never use
just fmt-rs-filefor 3+ files - Usejust fmt-rsfor efficiency
✅ Best Practices
- •Format before running checks/tests or before committing
- •Use
just fmt-rs-filefor 1-2 files (faster, targeted) - •Use
just fmt-rsfor 3+ files (more efficient) - •Use
just fmt-shafter editing theinstallscript - •Run format check commands to verify formatting before commits
Next Steps
After formatting your code:
- •Check compilation → See
.agents/skills/code-check/SKILL.md - •Run clippy → See
.agents/skills/code-check/SKILL.md - •Run targeted tests when warranted → See
.agents/skills/code-test/SKILL.md