clean-code-refactor

Refactor a single method to follow clean code principles without changing behavior.

Updated May 2, 2024
One-click install
npx skills add https://github.com/cman131/EatSomethingSourWhenYoureTired --skill clean-code-refactor-cman131
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: clean-code-refactor
Source: https://github.com/cman131/EatSomethingSourWhenYoureTired/tree/main/.claude/skills/clean-code-refactor
Command: npx skills add https://github.com/cman131/EatSomethingSourWhenYoureTired --skill clean-code-refactor-cman131

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Methods that mix parsing, validation, and business logic into one long block are hard to read, test, and maintain. This Skill restructures a single method so it reads as a high-level narrative backed by clearly named private helpers, while preserving exact behavior. ## Core Features & Use Cases - Principle-Driven Refactoring: Applies single responsibility, command/query separation, self-documenting naming, and guard clauses to restructure method internals. - Behavior Preservation Guarantee: Never renames the public method, changes its signature, or alters behavior; existing unit tests must still pass unmodified. - Self-Review Pass: Drafts the refactor, then re-applies every principle to the draft before presenting, catching leftover null checks, chained lookups, and nested error handling. - Use Case: You have a 60-line controller method that parses input, validates it, chains two database lookups, and logs at each step. Point the Skill at the file and method, and it proposes a short orchestrating public method with descriptively named helpers, keeping every log statement intact. ## Quick Start Refactor the ProcessOrder method in src/services/orderService.ts to follow clean code principles.

Frequently Asked Questions about clean-code-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a long method into smaller helper methods?▼

Identify distinct responsibilities such as parsing, validation, and business operations, then extract each into a descriptively named private helper. The public method should read as a high-level narrative of clearly named calls, using guard clauses to avoid deep nesting.

What is command query separation in clean code?▼

Command query separation means a method either changes state and returns nothing (a command) or returns data without side effects (a query). A method should not do both unless there is a compelling reason, such as an atomic pop from a collection.

Can refactoring change the public method signature?▼

No, this refactor only restructures internals and never renames the public method or changes its signature. Behavior must stay identical, so existing unit tests should pass without modification after the refactor.

When should I not extract code into a helper method?▼

Avoid extracting three lines of simple sequential logic just because the code exists. Extract only when there is a distinct responsibility, such as a parse-plus-validate cluster or a chained lookup that collapses into one named query.

Why did my unit tests fail after a structure-only refactor?▼

Failing tests after a structure-only refactor mean behavior changed during extraction. Fix the refactored code to restore the original behavior rather than modifying the tests to accommodate the new structure.