Identify and replace deprecated API usage in source code with modern alternatives. Use when: (1) Modernizing legacy codebases, (2) Upgrading framework versions (React, Django, Spring, etc.), (3) Fixing deprecation warnings in build output, (4) Preparing for major version upgrades, (5) Ensuring code uses current best practices. Supports Python, JavaScript/TypeScript, Java, and other major languages with both AST-based detection and pattern matching for accurate identification and automated replacement with validation.
93
92%
Does it follow best practices?
Impact
90%
1.60xAverage score across 3 eval scenarios
Passed
No known issues
Identify and replace deprecated API usage with modern alternatives automatically.
Scan code to identify deprecated API usage:
# Scan a single file
python scripts/detect_deprecated_apis.py src/app.py
# Scan entire directory
python scripts/detect_deprecated_apis.py src/
# Specify language explicitly
python scripts/detect_deprecated_apis.py legacy/ --language python
# Output as JSON
python scripts/detect_deprecated_apis.py src/ --format jsonAutomatically replace deprecated APIs:
# Dry run (preview changes)
python scripts/replace_deprecated_apis.py src/ --dry-run
# Apply replacements (creates .bak backups)
python scripts/replace_deprecated_apis.py src/
# Replace in specific language
python scripts/replace_deprecated_apis.py src/ --language javascriptSee python_deprecations.md for complete reference.
See javascript_deprecations.md for complete reference.
See java_deprecations.md for complete reference.
For Python and JavaScript, the skill uses Abstract Syntax Tree parsing for accurate detection:
Example: Detects os.popen() by analyzing the AST node structure, not just string matching.
For all languages, regex-based pattern matching provides fast detection:
Both methods are used together for comprehensive detection.
Run detection to identify deprecated APIs:
python scripts/detect_deprecated_apis.py src/Output example:
Found 3 deprecated API usage(s):
📍 src/utils.py:5:0
Deprecated: collections.Mapping
Replacement: collections.abc.Mapping
Context: from collections import Mapping
Detection: ast
📍 src/legacy.py:12:9
Deprecated: os.popen()
Replacement: subprocess.run() or subprocess.Popen()
Context: result = os.popen('ls')
Detection: astExamine the detected deprecations and suggested replacements. Check the reference documentation for detailed migration guides.
Preview changes before applying:
python scripts/replace_deprecated_apis.py src/ --dry-runOutput shows:
Apply changes with automatic backups:
python scripts/replace_deprecated_apis.py src/Creates:
.bak backup files for all modified filesCritical: Always validate after replacement:
# Run tests
npm test # JavaScript
pytest # Python
mvn test # Java
# Run linters
eslint src/ # JavaScript
flake8 src/ # Python
mvn checkstyle # Java
# Manual testing
# Test critical functionalityOnce validated:
# Review changes
git diff
# Commit
git add .
git commit -m "Replace deprecated APIs with modern alternatives"
# Remove backup files
find . -name "*.bak" -deletegit checkout -b fix/deprecated-apis.bak files until validatedDeprecations:
django.conf.urls.url → django.urls.pathforce_text() → force_str()ugettext → gettextProcess:
# Detect Django-specific deprecations
python scripts/detect_deprecated_apis.py myproject/ --language python
# Preview replacements
python scripts/replace_deprecated_apis.py myproject/ --dry-run
# Apply
python scripts/replace_deprecated_apis.py myproject/
# Test
python manage.py testDeprecations:
ReactDOM.render() → ReactDOM.createRoot()Process:
# Detect React deprecations
python scripts/detect_deprecated_apis.py src/ --language javascript
# Manual review needed for complex cases
# Some React upgrades require structural changes
# Apply simple replacements
python scripts/replace_deprecated_apis.py src/ --dry-run
python scripts/replace_deprecated_apis.py src/
# Test
npm test
npm start # Manual testingDeprecations:
collections.Mapping → collections.abc.Mappingtime.clock() → time.perf_counter()os.popen() → subprocess.run()Process:
# Scan codebase
python scripts/detect_deprecated_apis.py . --language python --format json > deprecations.json
# Review JSON output
cat deprecations.json
# Apply replacements
python scripts/replace_deprecated_apis.py . --dry-run
python scripts/replace_deprecated_apis.py .
# Run tests
pytestAlways manually review replacements for:
importlib.import_module('collections').Mappingimport collections as c; c.MappingProblem: Deprecations not detected
Solutions:
--language flag explicitlyProblem: False positives
Solutions:
Problem: Replacement breaks code
Solutions:
.bak filesProblem: Tests fail after replacement
Solutions:
Each guide includes:
To add custom deprecation patterns, edit the scripts:
scripts/detect_deprecated_apis.py:
DEPRECATION_PATTERNS = {
'python': [
# Add your patterns
(r'your\.deprecated\.api\(', 'your.deprecated.api()', 'modern.api()'),
]
}scripts/replace_deprecated_apis.py:
REPLACEMENT_RULES = {
'python': [
# Add your replacements
(r'your\.deprecated\.api\(', r'modern.api(', 'deprecated', 'modern'),
]
}Detect deprecations in CI:
# .github/workflows/deprecation-check.yml
name: Check Deprecations
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check for deprecated APIs
run: |
python scripts/detect_deprecated_apis.py src/ --format json > deprecations.json
if [ -s deprecations.json ]; then
echo "Deprecated APIs found!"
cat deprecations.json
exit 1
fiProcess multiple projects:
#!/bin/bash
for project in project1 project2 project3; do
echo "Processing $project..."
python scripts/detect_deprecated_apis.py "$project/src" > "$project-report.txt"
python scripts/replace_deprecated_apis.py "$project/src" --dry-run
done0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.