code-formatting
Provides code formatting best practices and granular edit operation guidelines. Use when formatting code, making edits to files, or when determining the proper approach for code modifications. Emphasizes using external formatting tools and breaking down large modifications into atomic, sequential edits for reliability.
When & Why to Use This Skill
This Claude skill optimizes code quality and reliability by enforcing industry-standard formatting practices and granular edit strategies. It guides AI agents to use external CLI tools like Prettier, Black, and jq for consistent styling while breaking down complex code modifications into atomic, manageable steps to minimize errors and ensure successful file updates.
Use Cases
- Automated Code Styling: Automatically applying language-specific formatters (e.g., Black for Python, Prettier for JavaScript) after code modifications to maintain project standards.
- Reliable Large-Scale Refactoring: Breaking down extensive code changes into sequential, granular edits (under 100 lines) to prevent operation failures and improve edit precision.
- JSON Data Management: Using specialized tools like jq to format and validate complex JSON configuration files after programmatic updates.
- Error Recovery in Code Editing: Implementing a retry strategy that decomposes failed large-scale edits into smaller, successful atomic operations to ensure incremental progress.
| name | code-formatting |
|---|---|
| description | Provides code formatting best practices and granular edit operation guidelines. Use when formatting code, making edits to files, or when determining the proper approach for code modifications. Emphasizes using external formatting tools and breaking down large modifications into atomic, sequential edits for reliability. |
Code Formatting and Structure
Guidelines for code formatting and structuring edit operations to ensure reliability and consistency.
Always Use External Tools for Formatting
- Use automated formatting tools consistently - rely on external CLI tools like
jq,prettier,black, etc. - After JSON edits:
jq . file.json > tmp && mv tmp file.json - After code edits: Use project-specific formatters (
npm run format,black,prettier, etc.) - This ensures consistent formatting and avoids human error
Common Formatting Tools by Language
JavaScript/TypeScript:
# Prettier
npx prettier --write file.js
# Project formatter
npm run format
Python:
# Black
black file.py
# isort for imports
isort file.py
JSON:
# jq for formatting
jq . file.json > tmp && mv tmp file.json
Go:
# gofmt
gofmt -w file.go
Rust:
# rustfmt
rustfmt file.rs
Granular Edit Operations
Break down large modifications into atomic, sequential edits:
- Single Edit: Limit to 50-100 lines maximum
- MultiEdit: Use 3-5 operations maximum per call
- Complex changes: Use multiple
Edit/MultiEditcalls in sequence - Failed edits: Immediately break into smaller operations and retry
Edit Strategy Pattern
Instead of this:
// DON'T: Large complex edit
Edit(entire_function)
Do this:
// DO: Sequential granular edits
Edit(function_signature)
Edit(function_body_part1)
Edit(function_body_part2)
When to Break Down Edits
Break down edits when:
- Modifying more than 50-100 lines at once
- Making changes to multiple logical sections
- Refactoring complex functions or classes
- An edit operation fails - immediately retry with smaller chunks
Benefits of Granular Edits
- Higher reliability: Smaller edits have fewer points of failure
- Better error messages: Easier to identify what went wrong
- Incremental progress: Partial success is better than complete failure
- Easier to verify: Each change can be validated independently
Workflow Integration
Typical formatting workflow:
- Make code changes using Edit/MultiEdit tools
- Apply automated formatter for the language
- Verify formatting is correct
- Proceed with next changes
Example:
# After editing Python file
black src/module.py
# After editing JavaScript
npx prettier --write src/component.js
# After editing JSON config
jq . config.json > tmp && mv tmp config.json
Key Principle
Rely on tools for formatting, rely on granularity for reliability. Never manually format code when automated tools are available, and always prefer smaller, focused edits over large, complex modifications.