home / skills / zpankz / mcp-skillset / code-refactoring

code-refactoring skill

/code-refactoring

This skill helps you refactor JavaScript code by decomposing large functions, simplifying logic, and removing redundancy to boost readability and

This is most likely a fork of the code-refactoring skill from baz-scm
npx playbooks add skill zpankz/mcp-skillset --skill code-refactoring

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.6 KB
---
name: code-refactoring
description: The practice of restructuring and simplifying code continuously – reducing complexity, improving design, and keeping codebases clean.
version: '1.0'
---
# Code Refactoring & Simplicity

Great developers continually refactor code to make it simpler and more efficient. Over time, software accumulates complexity; refactoring is the skill of untangling that complexity. By breaking down large functions and eliminating unnecessary logic, you improve readability and reduce technical debt. Simple designs are easier to test and evolve.

## Examples
- Splitting a 300-line function that does many things into smaller helper functions each focused on one task.
- Removing duplicate code by refactoring it into a reusable module or library.

## Guidelines
- **Decompose Large Functions:** If a function is doing too much or exceeds roughly 50 lines, split it into smaller, focused functions. Each function should ideally handle one responsibility. This makes the code easier to understand and test.
- **Simplify Complex Logic:** Reduce nesting and complexity in control flow. Apply the “exit early” principle to handle edge cases upfront and avoid deep nested `if`/`else` blocks. For example, return early on error conditions instead of wrapping the main logic in an else-clause.
- **Eliminate Redundancy:** Refactor to remove duplicate or convoluted code. Break down complex boolean expressions or chained operations into simpler steps. Simplifying tricky code by using clearer constructs or standard library functions makes it more approachable and reduces potential bugs.

Overview

This skill teaches continuous code refactoring and simplicity practices for JavaScript projects. It focuses on reducing complexity, improving design, and keeping codebases clean so features are easier to test and evolve. The guidance emphasizes practical techniques to lower technical debt and boost maintainability.

How this skill works

I inspect functions, modules, and control flow to identify complexity hotspots like long functions, deep nesting, duplication, and convoluted boolean logic. I recommend concrete refactors: splitting large functions, applying early returns, extracting reusable modules, and simplifying expressions. The result is smaller, focused functions and clearer code paths that are easier to review and test.

When to use it

  • When a function or file exceeds ~50 lines or handles multiple responsibilities
  • When you encounter deep nesting, complex conditional logic, or hard-to-follow control flow
  • When the codebase has duplicated logic across files or modules
  • Before writing tests or adding new features to reduce risk and clarify intent
  • When onboarding new developers or preparing code for production

Best practices

  • Decompose large functions into single-responsibility helpers that communicate intent
  • Apply the ‘exit early’ pattern to handle edge cases and avoid deep nesting
  • Extract repeated logic into reusable modules or utility functions
  • Replace complex chained expressions with intermediate named variables for clarity
  • Favor small, well-named functions and keep modules focused on one purpose

Example use cases

  • Split a 300-line handler into smaller validators, transformers, and a lean orchestrator
  • Refactor duplicated data parsing logic into a shared parser module
  • Replace nested if/else trees with guard clauses and early returns for error handling
  • Simplify a complex boolean expression by assigning parts to named constants
  • Refactor imperative loops into expressive array methods or small iterator helpers

FAQ

How small should functions be?

Aim for functions that do one thing and fit in short view—roughly under 50 lines—but prioritize clarity and single responsibility over rigid line counts.

Will refactoring change behavior?

Refactoring should preserve behavior; write or update tests before refactors to catch regressions and verify that intent is unchanged.