agentsclimarketplace

Dev refactor

Skill christopherlouet/claude-base/.claude/skills/dev-refactor

Opinionated Claude Code foundation — Explore → TDD → Audit workflow, auto-detected stack presets (nextjs, fastapi, astro, ...), curl | bash install. MIT.

Install
npx -y skills add christopherlouet/claude-base --skill dev-refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 5 stars5 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Code refactoring to improve quality. Trigger when the user wants to clean up, restructure, or improve existing code.

SKILL.md

3.6 KB, as published. Nobody here has run it

Code Refactoring

Principles

  1. Tests pass BEFORE and AFTER
  2. Small incremental changes
  3. One type of change at a time
  4. Commit after each refactoring

Common techniques

Extract Function

// Before
function processOrder(order) {
  // 20 lines of validation
  // 30 lines of calculation
  // 10 lines of sending
}

// After
function processOrder(order) {
  validateOrder(order);
  const total = calculateTotal(order);
  sendConfirmation(order, total);
}

Extract Variable

// Before
if (user.age >= 18 && user.country === 'FR' && !user.banned) { }

// After
const isAdult = user.age >= 18;
const isFrench = user.country === 'FR';
const isActive = !user.banned;
if (isAdult && isFrench && isActive) { }

Replace Conditional with Polymorphism

// Before
function getPrice(type) {
  switch(type) {
    case 'basic': return 10;
    case 'premium': return 20;
  }
}

// After
interface Plan { getPrice(): number }
class BasicPlan implements Plan { getPrice() { return 10; } }
class PremiumPlan implements Plan { getPrice() { return 20; } }

Code Smells to detect

SmellRefactoring
Long methodExtract Method
Large classExtract Class
Duplicate codeExtract + Reuse
Long parameter listParameter Object
Feature envyMove Method
Primitive obsessionValue Object

Reducing Entropy (Complexity reduction)

Complexity metrics

MetricAlert thresholdHow to measure
Cyclomatic complexity> 10 per functionNumber of branches (if/else/switch)
Nesting depth> 3 levelsNesting of if/for/while
Function length> 50 linesNumber of lines
Number of parameters> 4Function parameters
Afferent/efferent couplingUnstable ratioIncoming/outgoing dependencies
File size> 300 linesLines of code

Reduction techniques

Early Return (eliminate nesting)

// BEFORE: deep nesting (high entropy)
function process(user) {
  if (user) {
    if (user.isActive) {
      if (user.hasPermission) {
        return doWork(user);
      }
    }
  }
  return null;
}

// AFTER: early returns (low entropy)
function process(user) {
  if (!user) return null;
  if (!user.isActive) return null;
  if (!user.hasPermission) return null;
  return doWork(user);
}

Break down complex conditions

// BEFORE
if (user.age >= 18 && user.country === 'FR' && !user.banned && user.email.includes('@')) { }

// AFTER
const isEligible = user.age >= 18
  && user.country === 'FR'
  && !user.banned
  && isValidEmail(user.email);
if (isEligible) { }

Eliminate dead code

# Find unused exports
# Find functions never called
# Remove unused imports
# Remove obsolete comments
# Remove orphan files

Consolidate duplications

Rule of 3: refactor on the 3rd duplication, not before.
- 1st occurrence: write the code
- 2nd occurrence: note the duplication (comment)
- 3rd occurrence: extract into a function/module

Workflow

  1. MEASURE current complexity (metrics)
  2. Identify the code smell
  3. Write/verify tests
  4. Apply the refactoring
  5. MEASURE complexity after (must decrease)
  6. Verify tests
  7. Commit
  8. Repeat

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.