agentleFS
agentsdanceagentsdance/agentskills/skills/code-refactorer/SKILL.md

code-refactorer

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Refactor code for better readability, performance, and maintainability. Use when the user wants to improve code structure, reduce complexity, or apply design patterns.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Understand the code: - Read and comprehend current behavior

    line 68
  2. Distinctive:

    Write tests first: - Ensure behavior is preserved

    line 70

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Refactorer

Transform code to improve quality without changing behavior.

Refactoring Techniques

Extract Method

Turn code blocks into well-named functions:

# Before
def process_order(order):
    total = 0
    for item in order.items:
        total += item.price * item.quantity
    tax = total * 0.1
    return total + tax

# After
def calculate_subtotal(items):
    return sum(item.price * item.quantity for item in items)

def process_order(order):
    subtotal = calculate_subtotal(order.items)
    tax = subtotal * 0.1
    return subtotal + tax

Replace Conditionals with Polymorphism

# Before
def get_speed(vehicle_type):
    if vehicle_type == "car":
        return 120
    elif vehicle_type == "bike":
        return 25
    elif vehicle_type == "plane":
        return 900

# After
class Vehicle:
    def get_speed(self): pass

class Car(Vehicle):
    def get_speed(self): return 120

class Bike(Vehicle):
    def get_speed(self): return 25

Code Smells to Address

SmellSolution
Long MethodExtract smaller methods
Large ClassSplit into focused classes
Duplicate CodeExtract shared function
Long Parameter ListIntroduce parameter object
Feature EnvyMove method to appropriate class
Magic NumbersReplace with named constants

Process

  1. Understand the code - Read and comprehend current behavior
  2. Identify smells - Find areas needing improvement
  3. Write tests first - Ensure behavior is preserved
  4. Refactor incrementally - Small, safe changes
  5. Verify tests pass - Confirm no regressions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.