跳到正文
cccskills
免费在 GitHub 公开

refactor

Analyze files or modules for duplicated code, excessive complexity, and violations of SOLID, five software design principles. Get prioritized refactoring suggestions with affected locations, risks, estimated effort, and testing needs to guide code improvements.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Analyze code for SOLID violations and suggest targeted improvements

查看安装方法

适用场景

  • Reviewing responsibilities in oversized files and classes
  • Finding duplicated code and deeply nested logic
  • Prioritizing refactoring by impact, risk, and effort
  • Examining design patterns across a directory

包含的文件(1)

  • SKILL.md5.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

SOLID refactoring assistant

Analyze code for SOLID violations and suggest targeted improvements.

Purpose

Identify refactoring opportunities based on:

  • SOLID principle violations
  • Code smells and anti-patterns
  • Complexity metrics
  • Duplication detection

Instructions

Step 1: Scope analysis

Determine the refactoring scope from user input:

  • Single file: Deep analysis
  • Directory: Pattern detection across files
  • Function/class: Focused extraction suggestions
# Get file/directory stats
if [ -f "$TARGET" ]; then
  wc -l "$TARGET"
  echo "Single file analysis"
elif [ -d "$TARGET" ]; then
  find "$TARGET" -type f \( -name "*.ts" -o -name "*.js" -o -name "*.py" \) | wc -l
  echo "Directory analysis"
fi

Step 2: SOLID violations detection

S - single responsibility

Look for:

  • Files > 300 lines
  • Functions > 50 lines
  • Classes with > 10 methods
  • Mixed concerns (data + UI + business logic)
# Find large files
find . -name "*.{ts,js,py}" -exec wc -l {} + 2>/dev/null | sort -rn | head -10

# Functions with high line count (approximate)
grep -rn "function\|def \|fn " --include="*.{ts,js,py,rs}" . | head -20

O - open/closed principle

Look for:

  • Switch/case statements on types
  • Repeated if/else type checking
  • Direct modifications vs extensions

L - liskov substitution

Look for:

  • Overridden methods that throw "not implemented"
  • Type checks before method calls
  • Empty method overrides

I - interface segregation

Look for:

  • Large interfaces (> 10 methods)
  • Classes implementing unused interface methods
  • Fat service classes

D - dependency inversion

Look for:

  • Direct instantiation of dependencies (new Service())
  • Hardcoded class references
  • Missing dependency injection

Step 3: Code smells

# Duplication patterns
grep -rn --include="*.{ts,js,py}" . 2>/dev/null | \
  awk -F: '{print $3}' | sort | uniq -c | sort -rn | head -10

# Long parameter lists (> 4 params)
grep -rn "function.*,.*,.*,.*," --include="*.{ts,js}" . 2>/dev/null | head -10

# Deep nesting (4+ levels)
grep -rn "^\s\{16,\}" --include="*.{ts,js,py}" . 2>/dev/null | head -10

Step 4: Complexity assessment

For each issue found, assess:

  • Impact: How much code is affected?
  • Risk: What could break?
  • Effort: Lines to change, tests needed?

Output format


🔧 Refactoring analysis

Target: [file/directory] Lines Analyzed: [count]

📊 SOLID scorecard

PrincipleStatusIssues Found
Single Responsibility🟡3 large classes
Open/Closed🟢OK
Liskov Substitution🟢OK
Interface Segregation🔴2 fat interfaces
Dependency Inversion🟡5 direct instantiations

🎯 Priority refactorings

1. [Highest Impact] - Extract class from UserService

Violation: Single Responsibility Current: 450 lines handling auth + profile + notifications Suggested:

UserService.ts (450 lines)
    ↓ Extract
AuthService.ts (~150 lines)
ProfileService.ts (~150 lines)
NotificationService.ts (~100 lines)

Risk: Medium (update imports) Tests Needed: Update dependency injection in tests

2. [Second Priority] - Replace switch with polymorphism

Location: src/handlers/payment.ts:45 Current:

switch (paymentType) {
  case 'card': // 50 lines
  case 'bank': // 50 lines
  case 'crypto': // 50 lines
}

Suggested: Strategy pattern with PaymentProcessor interface Risk: Low (isolated change)

📝 Code smells

SmellLocationSeverity
Long Methodapi.ts:calculateTotal (120 lines)🟠 High
Duplicate Codeutils/*.ts (3 similar blocks)🟡 Medium
Deep Nestingparser.ts:parse (6 levels)🟡 Medium

🚀 Quick wins (low risk, high value)

  1. Extract validateEmail() to shared utils (used in 4 places)
  2. Replace magic numbers with named constants
  3. Add early returns to reduce nesting in processOrder()

⚠️ Technical debt notes

  • [Item to track for future sprints]

Refactoring safety checklist

Before applying suggestions:

  • Tests exist for affected code
  • Create feature branch
  • Commit current state
  • Apply one refactoring at a time
  • Run tests after each change
  • Review diff before committing

Usage

Analyze specific file:

/refactor src/services/user.ts

Analyze directory:

/refactor src/api/

Focus on specific principle:

/refactor --focus=srp src/services/

With complexity threshold:

/refactor --threshold=high

References

  • Martin Fowler's Refactoring Catalog
  • Clean Code by Robert C. Martin
  • SOLID principles by Robert C. Martin

$ARGUMENTS

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Evaluate Claude Code agents, skills, and commands with weighted quality criteria. Get scores, readiness grades, template comparisons, and practical improvement suggestions in Markdown or JSON reports to guide reviews before release.

中文简介正在准备中。当前显示英语简介。

  • Review skills before release
  • Compare agent definitions with reference templates
  • Quickly check critical quality criteria
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

Assess a codebase across seven areas, including exposed credentials, security, dependencies, structure, and tests. Receive category scores, findings tied to file locations, and a prioritized improvement plan with smaller tasks that can be completed quickly.

中文简介正在准备中。当前显示英语简介。

  • Assessing the overall health of an inherited project
  • Reviewing exposed credentials and security risks
  • Identifying dependency and test coverage gaps
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

Measure code patterns such as casts to any or disabled lint rules, then run repeated, targeted edits. Keep changes that improve the chosen metric, revert unsuccessful changes, and track results for each improvement loop.

中文简介正在准备中。当前显示英语简介。

  • Finding code patterns to prioritize for cleanup
  • Preparing measurement files for an improvement loop
  • Repeating targeted edits to reduce casts to any
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

best-of-n

免费

Generate several separate solutions, compare them against criteria fixed in advance, and verify the selected result through executable checks or an independent reviewer. Keep a proof log documenting candidates, evidence, failures, and remaining limits.

中文简介正在准备中。当前显示英语简介。

  • Comparing implementation options before choosing one
  • Verifying a solution when a wrong choice would be costly
  • Keeping evaluation evidence for delivery or audit
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

canary

免费

Monitor a live application after deployment and compare it with a saved baseline, a record of its earlier state. Check page responses, loading times, and new errors, flag persistent changes, and produce a per-page health report.

中文简介正在准备中。当前显示英语简介。

  • Recording a healthy baseline before deployment
  • Monitoring production immediately after deployment
  • Checking key pages for slower responses or failures
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

catchup

免费

Rebuild project context after clearing a conversation or returning to work. Review recent Git history, uncommitted changes, and TODO markers to get a structured summary of project status and suggested next steps.

中文简介正在准备中。当前显示英语简介。

  • Restoring project context after /clear
  • Reviewing recent changes after a long break
  • Checking unfinished work before choosing the next task
FlorianBruniaux/claude-code-ultimate-guide62022026年10月18日 更新

查看 FlorianBruniaux 的全部技能

报告此技能的问题