name: format-code description: Formats the codebase using nightly rustfmt. Use when asked to "format the code", "run rustfmt", "cargo fmt", or when formatting is needed after code changes. context: root user-invocable: true
Format Code
Description
Formats all Rust code in the codebase using nightly rustfmt to ensure consistent code style. This skill always uses nightly rustfmt to access the latest formatting features and configurations.
When to Use
- When asked to "format the code" or "format my code"
- When asked to "run rustfmt" or "cargo fmt"
- When asked to "fix formatting" or "clean up formatting"
- After completing code changes that need formatting
- Before committing changes to ensure consistent style
- When formatting issues are flagged by CI or pre-commit hooks
How It Works
Step 1: Run Nightly Rustfmt
Execute the format command using nightly toolchain:
cargo +nightly fmt
This formats all Rust files in the workspace according to the project's rustfmt.toml configuration (if present).
Step 2: Report Results
After formatting completes:
- If changes were made, inform the user that files were formatted
- If no changes were needed, confirm the code was already properly formatted
- Report any errors that occurred during formatting
Example Usage
User Request: "Format the code"
Expected Behavior:
Run formatter:
cargo +nightly fmtCheck for changes (optional):
git statusReport:
Code formatted successfully using nightly rustfmt.
User Request: "Run rustfmt before I commit"
Expected Behavior:
Run formatter:
cargo +nightly fmtReport:
Formatting complete. Ready to commit.
Best Practices
Do:
- Always use
cargo +nightly fmtto ensure nightly toolchain - Run formatting before committing changes
- Report whether any files were modified by the formatter
Don't:
- Use
cargo fmtwithout the+nightlyflag - Skip formatting when making code changes
- Ignore formatting errors
Quality Checklist
Before considering the task complete, verify:
- Ran
cargo +nightly fmtsuccessfully - No formatting errors were reported
- User is informed of the result
Troubleshooting
Nightly toolchain not installed:
- Run
rustup install nightlyto install - Then retry the format command
Formatting fails with parse errors:
- Check for syntax errors in the Rust code
- Fix compilation errors first, then format
rustfmt.toml issues:
- Verify the configuration file is valid
- Check that nightly-only options are supported
Related Skills
create-git-commit- Create commits after formatting- Code quality and linting workflows