- Home
- Skills
- Code Quality & Review
- refactoring
refactoring
Apply Martin Fowler's 68 standard refactoring techniques using a strict, test-first micro-step methodology.
Free
Works with the AI Agents you already use
refactoring
Example session with this skill installed
Refactor this processOrder function. It has 4 levels of nested if-statements and is about 50 lines long. Ensure the logic remains identical.
- Read your context and instructions
- Compiled the refactoring
I have analyzed the processOrder function and identified several smells, primarily Deep Nesting and Long Function. Following the "Two Hats" rule, I will now apply Extract Method and Replace Nested Conditional with Guard Clauses in atomic steps.
Refactoring Implementation
/**
* Refactored processOrder using Guard Clauses and Method Extraction.
* Verified: All edge cases (null order, invalid status, unauthorized)
* now return early, reducing cognitive load.
*/
function processOrder(order, user) {
if (!isValidOrder(order)) return { status: 400, message: "Invalid Order" };
if (!user.isAuthorized) return { status: 403, message: "Unauthorized" };
const subtotal = calculateSubtotal(order.items);
const total = applyTaxAndShipping(subtotal, order.shippingZone);
return saveOrderToDatabase(order.id, total);
}
// Private helper methods extracted to simplify the main flow
function isValidOrder(order) {
return order && order.items && order.items.length > 0;
}
function calculateSubtotal(items) {
return items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
}
function applyTaxAndShipping(subtotal, zone) {
const tax = subtotal * 0.08;
const shipping = zone === 'domestic' ? 5.00 : 25.00;
return subtotal + tax + shipping;
}
async function saveOrderToDatabase(id, total) {
// Database logic remains untouched to preserve behavior
return await db.orders.update(id, { total, status: 'processed' });
}
Next steps
1.
Run Unit Tests: Execute the existing test suite to verify that the return values for domestic vs international shipping remain unchanged.
2.
Review Helper Visibility: Decide if the extracted calculation methods should be exported for unit testing or remain private to the module.
3.
Check Side Effects: Confirm that saveOrderToDatabase still receives the exact same payload structure as the original version.
Connects securely to your tools. The creator never sees your data.
About this skill
Refactoring legacy code without introducing regressions is high-risk. This skill applies Martin Fowler's 68 classic refactoring patterns to restructure internal architecture while preserving external behavior through a strict, test-driven protocol.
What it does
- Smell detection identifies code smells like long functions, deep nesting, or high coupling.
- Pattern application executes specific techniques such as Extract Method, Move Field, or Replace Conditional with Guard Clauses.
- Micro-step execution breaks complex changes into atomic, verifiable steps to prevent side effects.
- Test scaffolding ensures a safety net by creating unit tests or verification demos before modifying any production logic.
- Refactoring mapping correlates identified code issues with the exact structural remedy needed.
How it works
- Identify the target and the specific code smell requiring attention.
- Build a test net by running existing tests or writing new verification demos to capture baseline behavior.
- Apply the pattern using atomic steps from the refactoring catalog.
- Iterate and verify by running tests after every single modification, rolling back immediately if a failure occurs.
Frameworks & tools
This skill is language-agnostic but follows the methodology defined in Martin Fowler's "Refactoring". It works with any tech stack where unit testing and modular code structures are applicable.
Why this beats prompting it yourself
Standard prompts often rewrite code from scratch, losing edge cases or introducing bugs. This skill enforces the "Two Hats" rule and "Baby Steps" methodology, ensuring structural improvement is decoupled from feature changes or bug fixes for maximum safety.
Use cases
- Simplify complex logic by converting deeply nested if-else blocks into clean guard clauses.
- Modularize monoliths by extracting long methods into focused, reusable private functions.
- Reduce technical debt by systematically applying documented patterns to legacy modules.
- Improve maintainability by reorganizing data and simplifying method calls without altering system output.
Known limitations
Requires a testable environment or the ability to run verification scripts. It will refuse to proceed with large-scale changes without a mechanism to verify behavior.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.
Requires a testable environment or the ability to run verification scripts. It will refuse to proceed with large-scale changes without a mechanism to verify behavior.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 13 days ago
- Free with an Agensi account
Permissions
No special permissions declared or detected