Refactoring Deprecated Code
Automatically detect and refactor deprecated library functions, APIs, and language features to modern alternatives.
What you should do
Scan for deprecation indicators – Systematically identify deprecated usage:
Compiler/Runtime Warnings:
- Capture deprecation warnings from build processes, linters, and IDEs
- Parse warning messages for specific deprecated functions and suggested replacements
- Identify severity levels (warnings vs. errors) and timeline for removal
Static Code Analysis:
- Search for known deprecated patterns using language-specific tools:
- Python:
bandit, pylint, mypy for deprecated library usage
- JavaScript/Node.js: ESLint rules, TypeScript compiler warnings
- Java: SpotBugs, PMD, or IDE deprecation annotations
- Go:
go vet, staticcheck for deprecated usage
- Rust: Clippy warnings and compiler deprecation notices
Documentation and Changelog Review:
- Review library changelogs for deprecation announcements
- Check migration guides and upgrade documentation
- Identify deprecation timelines and recommended alternatives
Categorize deprecated usage by impact – Organize findings systematically:
Severity Classification:
- Critical: APIs scheduled for removal in next major version
- High: Functions deprecated for >1 year or with security implications
- Medium: Recently deprecated functions with clear alternatives
- Low: Soft deprecations or style preference changes
Usage Analysis:
- Count occurrences of each deprecated function across the codebase
- Identify high-frequency usage patterns requiring batch updates
- Map dependencies between deprecated APIs and application logic
- Assess complexity of required refactoring for each deprecation
Research modern alternatives and migration paths – Identify replacement strategies:
Direct Replacements:
- Simple function/method renames with identical signatures
- Updated import paths or module names
- Parameter order changes or new required parameters
- Return value format changes requiring minimal adaptation
Complex Migrations:
- API paradigm shifts (e.g., synchronous to asynchronous)
- Architectural changes (e.g., callback-based to Promise-based)
- Configuration format updates (e.g., JSON to YAML, environment variables)
- Framework migration patterns (e.g., class-based to functional components)
Create automated refactoring scripts – Develop transformation tools:
Language-Specific Refactoring Tools:
- Python: Use
ast module, libcst, or rope for code transformation
- JavaScript: Leverage
jscodeshift, Babel transforms, or ESLint autofix rules
- Java: Utilize OpenRewrite, Refaster, or IDE refactoring APIs
- Go: Use
gofmt, gorename, or custom AST manipulation
- Rust: Apply
cargo fix or custom syntax tree transformations
Pattern-Based Replacements:
- Create regex-based find-and-replace for simple cases
- Develop AST-based transformations for complex structural changes
- Handle edge cases like nested calls, conditional usage, or exception handling
Implement refactoring in phases – Execute systematic transformation:
Phase 1 - Low-Risk Direct Replacements:
- Start with simple function renames and import updates
- Apply automated transformations to straightforward patterns
- Update configuration files and static references
- Test each batch of changes before proceeding
Phase 2 - Medium Complexity Migrations:
- Refactor API usage patterns requiring parameter changes
- Update error handling and return value processing
- Modify configuration and initialization patterns
- Validate functionality with comprehensive testing
Phase 3 - High Complexity Architectural Changes:
- Implement paradigm shifts (sync to async, callback to Promise)
- Refactor large-scale architectural patterns
- Update related documentation and examples
- Perform extensive integration and regression testing
Validate refactoring accuracy – Ensure correctness and completeness:
Automated Testing:
- Run full test suite after each refactoring phase
- Execute integration tests to verify external API interactions
- Perform regression testing to catch behavioral changes
- Use property-based testing for complex transformations
Manual Verification:
- Review critical code paths and complex transformations manually
- Verify that edge cases and error conditions are handled correctly
- Check that performance characteristics remain acceptable
- Ensure logging and debugging functionality still works
Update documentation and dependencies – Maintain project consistency:
Dependency Management:
- Update
package.json, requirements.txt, or similar manifest files
- Remove deprecated dependencies and add new required packages
- Update minimum version requirements for upgraded libraries
- Resolve version conflicts and peer dependency issues
Documentation Updates:
- Update code comments referring to deprecated functions
- Revise README files with new usage examples
- Update API documentation and development guides
- Create migration notes for other developers
Integrate findings into existing roadmap – Thoughtfully update ROADMAP.md:
Review existing maintenance initiatives:
- Read current ROADMAP.md to understand planned dependency updates
- Identify existing refactoring, modernization, or technical debt initiatives
- Understand current maintenance priorities and resource allocation
Merge deprecation findings intelligently:
- Consolidate with existing library upgrade and maintenance work
- Integrate high-priority deprecations with existing quality improvement initiatives
- Balance deprecation fixes with new feature development based on project priorities
- Update timeline estimates considering deprecation urgency and complexity
Create prevention measures – Establish ongoing deprecation management:
Automated Detection:
- Add deprecation warnings to CI/CD pipeline checks
- Configure dependency scanning tools to flag deprecated packages
- Set up automated alerts for new deprecation announcements
- Create regular scheduled scans for emerging deprecations
Team Practices:
- Document preferred alternatives to commonly deprecated patterns
- Add deprecation awareness to code review checklists
- Establish dependency update policies and schedules
- Train team on recognizing and avoiding deprecated usage
LANGUAGE-SPECIFIC DEPRECATION PATTERNS:
Python:
- Function/method renames and module reorganizations
- Parameter changes and new argument requirements
- Import path updates (e.g.,
imp → importlib)
- String formatting evolution (
% → .format() → f-strings)
JavaScript/Node.js:
- Browser API changes and polyfill requirements
- Package.json script updates and tooling migrations
- Framework version updates (React, Vue, Angular)
- Node.js built-in module changes and new APIs
Java:
- Deprecated annotation handling and replacement identification
- Library migration patterns (e.g., Date → LocalDateTime)
- Build tool updates (Maven, Gradle plugin deprecations)
- Spring Framework and enterprise library evolution
MIGRATION BEST PRACTICES:
- Incremental approach: Migrate in small, testable batches
- Backward compatibility: Maintain compatibility during transition periods
- Comprehensive testing: Validate each change thoroughly
- Documentation: Record migration decisions and rationale
- Team communication: Keep stakeholders informed of breaking changes
DELIVERABLES:
For each deprecation refactoring session:
- Updated ROADMAP.md: Integrated deprecation fixes within unified project maintenance plan
- Migration summary: List of deprecated functions updated and alternatives adopted
- Test validation report: Evidence that refactoring maintains functionality
- Prevention strategy: Measures to catch future deprecations early
The goal is to systematically eliminate deprecated code usage while maintaining functionality, improving maintainability, and establishing processes to prevent future deprecation accumulation.
1---2name: refactoring-deprecated-code3description: Systematically scans for deprecated library functions, APIs, and language features, then automatically updates code to use modern alternatives. Handles migration guides, version compatibility, and integration testing. Use when detecting deprecation warnings, updating dependencies, addressing API evolution, or when the user mentions deprecated APIs, legacy code, or migration needs.4---5
6# Refactoring Deprecated Code
7
8Automatically detect and refactor deprecated library functions, APIs, and language features to modern alternatives.
9
10## What you should do
11
121. **Scan for deprecation indicators** – Systematically identify deprecated usage:
13
14 **Compiler/Runtime Warnings:**
15 - Capture deprecation warnings from build processes, linters, and IDEs
16 - Parse warning messages for specific deprecated functions and suggested replacements
17 - Identify severity levels (warnings vs. errors) and timeline for removal
18
19 **Static Code Analysis:**
20 - Search for known deprecated patterns using language-specific tools:
21 - Python: `bandit`, `pylint`, `mypy` for deprecated library usage
22 - JavaScript/Node.js: ESLint rules, TypeScript compiler warnings
23 - Java: SpotBugs, PMD, or IDE deprecation annotations
24 - Go: `go vet`, staticcheck for deprecated usage
25 - Rust: Clippy warnings and compiler deprecation notices
26
27 **Documentation and Changelog Review:**
28 - Review library changelogs for deprecation announcements
29 - Check migration guides and upgrade documentation
30 - Identify deprecation timelines and recommended alternatives
31
322. **Categorize deprecated usage by impact** – Organize findings systematically:
33
34 **Severity Classification:**
35 - **Critical**: APIs scheduled for removal in next major version
36 - **High**: Functions deprecated for >1 year or with security implications
37 - **Medium**: Recently deprecated functions with clear alternatives
38 - **Low**: Soft deprecations or style preference changes
39
40 **Usage Analysis:**
41 - Count occurrences of each deprecated function across the codebase
42 - Identify high-frequency usage patterns requiring batch updates
43 - Map dependencies between deprecated APIs and application logic
44 - Assess complexity of required refactoring for each deprecation
45
463. **Research modern alternatives and migration paths** – Identify replacement strategies:
47
48 **Direct Replacements:**
49 - Simple function/method renames with identical signatures
50 - Updated import paths or module names
51 - Parameter order changes or new required parameters
52 - Return value format changes requiring minimal adaptation
53
54 **Complex Migrations:**
55 - API paradigm shifts (e.g., synchronous to asynchronous)
56 - Architectural changes (e.g., callback-based to Promise-based)
57 - Configuration format updates (e.g., JSON to YAML, environment variables)
58 - Framework migration patterns (e.g., class-based to functional components)
59
604. **Create automated refactoring scripts** – Develop transformation tools:
61
62 **Language-Specific Refactoring Tools:**
63 - Python: Use `ast` module, `libcst`, or `rope` for code transformation
64 - JavaScript: Leverage `jscodeshift`, Babel transforms, or ESLint autofix rules
65 - Java: Utilize OpenRewrite, Refaster, or IDE refactoring APIs
66 - Go: Use `gofmt`, `gorename`, or custom AST manipulation
67 - Rust: Apply `cargo fix` or custom syntax tree transformations
68
69 **Pattern-Based Replacements:**
70 - Create regex-based find-and-replace for simple cases
71 - Develop AST-based transformations for complex structural changes
72 - Handle edge cases like nested calls, conditional usage, or exception handling
73
745. **Implement refactoring in phases** – Execute systematic transformation:
75
76 **Phase 1 - Low-Risk Direct Replacements:**
77 - Start with simple function renames and import updates
78 - Apply automated transformations to straightforward patterns
79 - Update configuration files and static references
80 - Test each batch of changes before proceeding
81
82 **Phase 2 - Medium Complexity Migrations:**
83 - Refactor API usage patterns requiring parameter changes
84 - Update error handling and return value processing
85 - Modify configuration and initialization patterns
86 - Validate functionality with comprehensive testing
87
88 **Phase 3 - High Complexity Architectural Changes:**
89 - Implement paradigm shifts (sync to async, callback to Promise)
90 - Refactor large-scale architectural patterns
91 - Update related documentation and examples
92 - Perform extensive integration and regression testing
93
946. **Validate refactoring accuracy** – Ensure correctness and completeness:
95
96 **Automated Testing:**
97 - Run full test suite after each refactoring phase
98 - Execute integration tests to verify external API interactions
99 - Perform regression testing to catch behavioral changes
100 - Use property-based testing for complex transformations
101
102 **Manual Verification:**
103 - Review critical code paths and complex transformations manually
104 - Verify that edge cases and error conditions are handled correctly
105 - Check that performance characteristics remain acceptable
106 - Ensure logging and debugging functionality still works
107
1087. **Update documentation and dependencies** – Maintain project consistency:
109
110 **Dependency Management:**
111 - Update `package.json`, `requirements.txt`, or similar manifest files
112 - Remove deprecated dependencies and add new required packages
113 - Update minimum version requirements for upgraded libraries
114 - Resolve version conflicts and peer dependency issues
115
116 **Documentation Updates:**
117 - Update code comments referring to deprecated functions
118 - Revise README files with new usage examples
119 - Update API documentation and development guides
120 - Create migration notes for other developers
121
1228. **Integrate findings into existing roadmap** – Thoughtfully update `ROADMAP.md`:
123
124 **Review existing maintenance initiatives:**
125 - Read current ROADMAP.md to understand planned dependency updates
126 - Identify existing refactoring, modernization, or technical debt initiatives
127 - Understand current maintenance priorities and resource allocation
128
129 **Merge deprecation findings intelligently:**
130 - Consolidate with existing library upgrade and maintenance work
131 - Integrate high-priority deprecations with existing quality improvement initiatives
132 - Balance deprecation fixes with new feature development based on project priorities
133 - Update timeline estimates considering deprecation urgency and complexity
134
1359. **Create prevention measures** – Establish ongoing deprecation management:
136
137 **Automated Detection:**
138 - Add deprecation warnings to CI/CD pipeline checks
139 - Configure dependency scanning tools to flag deprecated packages
140 - Set up automated alerts for new deprecation announcements
141 - Create regular scheduled scans for emerging deprecations
142
143 **Team Practices:**
144 - Document preferred alternatives to commonly deprecated patterns
145 - Add deprecation awareness to code review checklists
146 - Establish dependency update policies and schedules
147 - Train team on recognizing and avoiding deprecated usage
148
149**LANGUAGE-SPECIFIC DEPRECATION PATTERNS:**
150
151**Python:**
152- Function/method renames and module reorganizations
153- Parameter changes and new argument requirements
154- Import path updates (e.g., `imp` → `importlib`)
155- String formatting evolution (`%` → `.format()` → f-strings)
156
157**JavaScript/Node.js:**
158- Browser API changes and polyfill requirements
159- Package.json script updates and tooling migrations
160- Framework version updates (React, Vue, Angular)
161- Node.js built-in module changes and new APIs
162
163**Java:**
164- Deprecated annotation handling and replacement identification
165- Library migration patterns (e.g., Date → LocalDateTime)
166- Build tool updates (Maven, Gradle plugin deprecations)
167- Spring Framework and enterprise library evolution
168
169**MIGRATION BEST PRACTICES:**
170
171- **Incremental approach**: Migrate in small, testable batches
172- **Backward compatibility**: Maintain compatibility during transition periods
173- **Comprehensive testing**: Validate each change thoroughly
174- **Documentation**: Record migration decisions and rationale
175- **Team communication**: Keep stakeholders informed of breaking changes
176
177**DELIVERABLES:**
178
179For each deprecation refactoring session:
180- **Updated ROADMAP.md**: Integrated deprecation fixes within unified project maintenance plan
181- **Migration summary**: List of deprecated functions updated and alternatives adopted
182- **Test validation report**: Evidence that refactoring maintains functionality
183- **Prevention strategy**: Measures to catch future deprecations early
184
185The goal is to systematically eliminate deprecated code usage while maintaining functionality, improving maintainability, and establishing processes to prevent future deprecation accumulation.