Review And Refactor
review-and-refactor skill for programming & development
An AI skill that combines code review and refactoring into a single workflow, analyzing code for quality issues and automatically applying improvements while preserving functionality, streamlining the process of maintaining clean codebases.
What Is This?
Overview
This skill performs a two phase operation on your code. First it reviews for issues like poor naming, excessive complexity, duplication, and style violations. Then it applies targeted refactoring to fix each issue. The result is cleaner code alongside a report explaining every change.
Who Should Use This
Best suited for developers who want actionable code reviews rather than just comments, teams without dedicated reviewers, and solo developers seeking a second pair of eyes.
Why Use It?
Problems It Solves
Traditional code reviews identify problems but leave fixes to the developer. This creates a gap where improvements get deprioritized or forgotten. By combining review and refactoring, this skill ensures every issue is addressed immediately.
Core Highlights
- Integrated Workflow reviews and refactors in a single operation
- Actionable Output every finding comes with an applied fix, not just a comment
- Change Report documents what was changed and why for team transparency
- Safety Checks verifies that refactored code preserves original behavior
- Style Consistency applies project conventions uniformly across the codebase
How to Use It?
Basic Usage
Submit code for review and receive both the analysis and the improved version.
def calc(d):
t = 0
for i in d:
if i["type"] == "sale":
t = t + i["amount"]
elif i["type"] == "refund":
t = t - i["amount"]
elif i["type"] == "tax":
t = t + (i["amount"] * 0.1)
return t
TRANSACTION_MULTIPLIERS = {
"sale": 1,
"refund": -1,
"tax": 0.1,
}
def calculate_total(transactions):
total = 0
for transaction in transactions:
multiplier = TRANSACTION_MULTIPLIERS.get(transaction["type"], 0)
total += transaction["amount"] * multiplier
return total
Real-World Examples
Express API Controller Cleanup
A team ran review and refactor on their user controller before a sprint review. The skill identified 12 issues including inconsistent error responses, duplicated validation logic, and missing input sanitization. It consolidated error handling into a shared utility, extracted validation into middleware, and added sanitization at the entry points.
// Before: scattered error handling
app.get("/users/:id", async (req, res) => {
try {
const user = await db.findUser(req.params.id);
if (!user) return res.status(404).json({ msg: "not found" });
res.json(user);
} catch (e) {
res.status(500).json({ msg: "error" });
}
});
// After: consistent error handling via middleware
app.get("/users/:id", validateId("id"), async (req, res, next) => {
const user = await db.findUser(req.params.id);
if (!user) throw new NotFoundError("User not found");
res.json(user);
});Advanced Tips
Run the skill on individual modules rather than entire codebases for focused changes. Configure severity thresholds to filter minor style issues when focusing on structural problems.
When to Use It?
Use Cases
- Pre Merge Cleanup improve code quality before merging feature branches
- Legacy Improvement systematically clean up older modules
- Learning Tool see concrete examples of how your code can be improved
- Consistency Enforcement align code style across contributors
- Technical Debt Sprints process entire directories in batch mode
Related Topics
When working with review and refactor, these prompts activate the skill:
- "Review and refactor this code"
- "Clean up this module with explanations"
- "Find issues in this code and fix them"
- "Improve this function and tell me what you changed"
Important Notes
Requirements
- Works with all major programming languages and frameworks
- Most effective when the project has established coding conventions to reference
- Benefits from an existing test suite to validate refactored behavior
- Version control recommended so changes can be reviewed before committing
Usage Recommendations
Do:
- Review the change report before accepting all modifications
- Run tests after applying changes to confirm nothing broke
- Focus on one module at a time for manageable review cycles
- Use severity filters to prioritize critical issues over style preferences
Don't:
- Accept all changes blindly as some refactors may conflict with intentional patterns
- Run on untested code since there is no safety net to catch behavior changes
- Combine with manual edits in the same commit as this complicates tracking
- Ignore the review report since understanding why changes were made builds skill
Limitations
- Cannot detect business logic errors that require domain expertise to identify
- Refactored code may not match personal style preferences in every case
- Very tightly coupled code may require manual intervention beyond automated fixes
- Performance sensitive code needs benchmarking after structural changes
More Skills You Might Like
Explore similar skills to enhance your workflow
Make Skill Template
make-skill-template skill for programming & development
Kubernetes Manifest Generator
- Define Service resources for network connectivity
Expo Cicd Workflows
Set up continuous integration and deployment workflows for Expo applications
Code Transfer
Transfer code between files with line-based precision. Use when users request copying code from one location to another, moving functions or classes b
Technical Doc Creator
Create HTML technical documentation with code blocks, API workflows, system architecture diagrams, and syntax highlighting. Use when users request tec
Markdown To HTML
markdown-to-html skill for programming & development