Refactor Legacy Code

aj-geddes/useful-ai-prompts/skills/refactor-legacy-code

作者 aj-geddes3f5182cfd739无许可证355 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

Modernize and improve legacy codebases while maintaining functionality. Use when you need to refactor old code, reduce technical debt, modernize deprecated patterns, or improve code maintainability without breaking existing behavior.

AI 生成的概览

指导在保持现有行为的前提下系统重构遗留代码库。

功能
该技能提供一套结构化的遗留代码现代化方法:评估代码库、建立测试安全网、增量重构、现代化过时模式并减少依赖。它附带覆盖各阶段的参考指南和一个完整示例,以及一个测试脚手架 shell 脚本和一个 JavaScript 测试模板。产出是用于提升可维护性、可读性和性能而不改变功能的指导与配套工件。
适用场景
适用于现代化过时的代码模式或已弃用的 API、减少技术债务、提升可读性与可维护性、从单体代码中抽取可复用组件,或为新功能开发做准备。它适合必须保持现有行为、且需要在改动前建立测试的场景。
运行要求
需要能够读取随附参考指南并运行随附脚本(scripts/scaffold-tests.sh 和 templates/test-template.js)的智能体环境。快速开始部分提到 tree、npm outdated 或 pip list --outdated 以及 linter 或 SonarQube 等外部工具,但该技能本身不需要凭据或网络访问。

Refactor Legacy Code

Table of Contents

Overview

This skill helps you systematically refactor legacy code to improve maintainability, readability, and performance while preserving existing functionality. It follows industry best practices for safe refactoring with comprehensive testing.

When to Use

  • Modernizing outdated code patterns or deprecated APIs
  • Reducing technical debt in existing codebases
  • Improving code readability and maintainability
  • Extracting reusable components from monolithic code
  • Upgrading to newer language features or frameworks
  • Preparing code for new feature development

Quick Start

First, analyze the legacy code to understand:

bash
# Review the codebase structuretree -L 3 -I 'node_modules|dist|build'
# Check for outdated dependenciesnpm outdated  # or pip list --outdated, composer outdated, etc.
# Identify code complexity hotspots# Use tools like:# - SonarQube for code smells# - eslint for JavaScript# - pylint for Python# - RuboCop for Ruby

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Code Assessment [blocked]Code Assessment
Establish Safety Net [blocked]Establish Safety Net
Incremental Refactoring [blocked]Incremental Refactoring
Modernize Patterns [blocked]Modernize Patterns
Reduce Dependencies [blocked]Reduce Dependencies, Documentation
Complete Refactoring Example [blocked]Complete Refactoring Example
Benefits Achieved [blocked]Benefits Achieved

Best Practices

✅ DO

  • Refactor incrementally: Small, testable changes
  • Run tests frequently: After each refactoring step
  • Commit often: Create logical, atomic commits
  • Keep existing tests passing: Don't break functionality
  • Use IDE refactoring tools: Safer than manual edits
  • Review code coverage: Ensure tests cover refactored code
  • Document decisions: Why, not just what
  • Seek peer review: Fresh eyes catch issues

❌ DON'T

  • Mix refactoring with new features: Separate concerns
  • Refactor without tests: Recipe for breaking changes
  • Change behavior: Refactoring should preserve functionality
  • Refactor large chunks: Increases risk and review difficulty
  • Ignore code smells: Address them systematically
  • Skip documentation: Future maintainers need context

来源与署名

来源:aj-geddes/useful-ai-prompts位于skills/refactor-legacy-code提交3f5182c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架