agentleFS
kwhornekwhorne/elyra-skills/skills/refactoring/SKILL.md

refactoring

Skill1 starsChanged 6 months agoMITView on GitHub

Refactor code safely with characterization tests first, small reversible steps, and verification after each step. Use when the user asks to refactor, restructure, clean up, simplify, extract, or rename existing code.

39 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use performance, ci-cd and 5 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • pluginagentmarketplaceSkill

    performance

    Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.

    Also in 7 projects that use this

  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 4 projects that use this

  • CloudAI-XSkill

    database-design

    Designs database schemas, indexing strategies, query optimization, and migration patterns for SQL and NoSQL databases. Use when designing tables, optimizing queries, fixing N+1 problems, planning migrations, or when asked about database performance, normalization, ORMs, or data modeling.

    Also in 5 projects that use this

  • AnthropicSkill

    documentation

    Write and maintain technical documentation. Trigger with "write docs for", "document this", "create a README", "write a runbook", "onboarding guide", or when the user needs help with any form of technical writing — API docs, architecture docs, or operational runbooks.

    Also in 8 projects that use this

  • ElasticSkill

    accessibility

    Accessibility guidance for Kibana. Use this skill when working with or reviewing EUI components, resolving a11y-related (@elastic/eui) ESLint issues, and ensuring proper use of ARIA attributes, focus management, keyboard interactions, and accessible naming conventions.

    Also in 5 projects that use this

  • NVIDIASkill

    testing

    Run Python and Rust tests for physicsnemo-curator using uv + pytest with coverage reporting via pytest-cov, and cargo-nextest for Rust tests. Includes benchmark workflows with pytest-benchmark and criterion.

    Also in 10 projects that use this

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 34 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If you can't get to step 1 or 2, stop and tell the user.

    line 51
  2. Distinctive:

    Commit (or at least stash) after each green step.

    line 61
  3. Distinctive:

    All tests pass (including ones you wrote in step 1)

    line 80
  4. Distinctive:

    No dead code left over

    line 82
  5. Distinctive:

    Run a diff stat: large diff is fine, surprises are not

    line 83
  6. Very specific:

    If the test suite is slow, scope down: pytest path/to/affected, vitest run src/affected/, etc.

    line 114
  7. Distinctive:

    Use the IDE/LSP refactor tools for renames and moves when available — they're more reliable than text search-replace.

    line 115
  8. Distinctive:

    If a refactor "needs" you to change a test, pause: are you changing behavior?

    line 116

“Common” is measured: kept by at least 6 in 10 of the 34 edited versions of this file we could read. “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

Refactoring

Refactoring: changing the structure of code without changing its observable behavior.

The discipline is in the without. If tests fail or behavior changes, it's no longer a refactor — it's a rewrite, and it needs to be reviewed as one.

When to use

  • "Refactor X"
  • "Clean up / simplify / restructure …"
  • "Extract this into a function/module/class"
  • "Rename / move / split …"
  • "Reduce duplication"

When NOT to use

  • The user wants new behavior → that's a feature, not a refactor
  • There are no tests and no time/permission to add them → flag the risk first
  • The code is going to be deleted soon → don't polish it

Procedure

0. Confirm scope and goal

Refactoring is open-ended. Pin it down:

  • What's the smell? (duplication, long function, unclear naming, tight coupling, …)
  • What does "done" look like?
  • What must not change? (public API, file paths, performance, …)

1. Establish a safety net

Behavior preservation needs proof. In order of preference:

  1. Existing tests that cover the affected code. Run them; they must pass before you start.
  2. Characterization tests — write tests that pin down current behavior (including warts), so you'll notice if you change it.
  3. Manual repro of key paths if tests are impossible. Document what you checked.

If you can't get to step 1 or 2, stop and tell the user. Don't refactor on faith.

2. Refactor in small steps

Each step:

  • Is one transformation (extract, rename, inline, move, …)
  • Compiles / lints / type-checks
  • Passes the test suite

Commit (or at least stash) after each green step. If a step turns red, revert it — don't pile fixes on top.

3. Common refactoring moves

MoveUse when
Extract functionA block of code has a clear single purpose and a good name suggests itself
InlineA function adds no clarity over its body
RenameThe current name lies, lags, or shrugs
MoveA function sits closer to data it doesn't use than data it does
Replace conditional with polymorphismA switch/if chain on type repeats in multiple places
Introduce parameter objectA function takes 4+ related args, or the same cluster appears together repeatedly
Replace magic value with named constantA literal appears more than once or its meaning isn't obvious
Split phaseOne function does parsing and processing, or fetch and transform

4. Verify

After all steps:

  • All tests pass (including ones you wrote in step 1)
  • Public API unchanged (or changes are deliberate and documented)
  • No dead code left over
  • Run a diff stat: large diff is fine, surprises are not

5. Stop

Refactoring is open-ended; that's why it's dangerous. Stop at the goal you set in step 0. If you spot more smells, note them, don't fix them now.

Output format

## Refactor: <short title>

**Goal:** what we set out to do.

**Approach:** sequence of small steps actually taken.

**Behavior preservation:** tests run / written / checked.

**Out of scope (noted, not fixed):** other smells you spotted.

Anti-patterns

  • ❌ "Refactor + add a feature in the same change" — split into two PRs
  • ❌ Big-bang rewrite labeled as "refactor"
  • ❌ Refactoring without running the tests after each step
  • ❌ Renaming things at the same time as moving them at the same time as changing signatures
  • ❌ Polishing code that's about to be deleted
  • ❌ Reformatting unrelated code — keep diffs reviewable

Tips

  • If the test suite is slow, scope down: pytest path/to/affected, vitest run src/affected/, etc. But run the full suite at the end.
  • Use the IDE/LSP refactor tools for renames and moves when available — they're more reliable than text search-replace.
  • If a refactor "needs" you to change a test, pause: are you changing behavior? If yes, label it as such.

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.