capabilities:
- python code smell detection (god functions, long parameters, deep nesting, etc.)
- solidity smart contract anti-patterns (reentrancy, unchecked arithmetic, etc.)
- cyclomatic complexity calculation per function
- maintainability index scoring (0-100)
- specific refactoring recommendations with code examples
- automatic unit test generation
- security pattern detection
- test strategy planning
- code quality metrics and reporting
security_considerations:
- Read-only code analysis (no code execution)
- No external file access
- Pattern-based detection only
- Safe AST parsing with error handling
- No sensitive data exposure
- No code modification without user confirmation
- Sandbox analysis environment
Overview
The Code Refactoring Advisor is an enterprise-grade code quality tool that analyzes Python and Solidity code to detect smells, anti-patterns, and complexity issues with actionable refactoring recommendations. It combines pattern detection, complexity metrics, and test generation to improve code quality systematically.
Key capabilities:
- Code Smell Detection: 12+ patterns (god functions, long parameters, deep nesting, etc.)
- Complexity Analysis: Cyclomatic complexity and maintainability index calculation
- Refactoring Recommendations: Specific solutions with code examples and effort estimates
- Test Generation: Automatic unit and integration test case generation
- Security Patterns: Solidity vulnerability detection (reentrancy, arithmetic, etc.)
Module Details
Module 1: Pattern Detector (92% Confidence)
Detects code smells and anti-patterns in Python and Solidity:
- Python: God functions, long parameter lists, deep nesting, bare excepts, global variables, magic numbers
- Solidity: Reentrancy vulnerabilities, unbounded loops, unchecked arithmetic, unclear visibility
- Outputs: Severity levels (CRITICAL/HIGH/MEDIUM/LOW), confidence scores, line numbers
Module 2: Refactoring Suggester (88% Confidence)
Generates specific refactoring solutions:
- Pattern-based recommendations (extract method, parameter object, strategy pattern, etc.)
- Effort estimates (TRIVIAL to LARGE)
- Benefits per refactoring (testability, maintainability, security, etc.)
- Code examples showing before/after
Module 3: Complexity Analyzer (90% Confidence)
Calculates code metrics:
- Cyclomatic complexity per function
- Maintainability Index (0-100)
- Code statistics (lines, comments, ratio)
- Health scoring and improvement recommendations
Module 4: Test Generator (85% Confidence)
Creates test cases for refactored code:
- Unit tests (extracted methods, parameters, guards)
- Integration tests (combined functionality)
- Security tests (reentrancy, edge cases)
- Test templates and strategies
Usage Examples
Detect Code Smells
from scripts.pattern_detector import PatternDetector
detector = PatternDetector()
result = detector.analyze_code(source_code, language="python")
print(f"Smells found: {result['smells_detected']}")
print(f"Code quality: {result['code_quality']}%")
Get Refactoring Recommendations
from scripts.refactoring_suggester import RefactoringSuggester
suggester = RefactoringSuggester()
suggestions = suggester.suggest_refactoring(smell_data)
for suggestion in suggestions['suggestions']:
print(f"{suggestion['smell_type']}: {suggestion['solutions']}")
Analyze Complexity
from scripts.complexity_analyzer import ComplexityAnalyzer
analyzer = ComplexityAnalyzer()
metrics = analyzer.analyze_module(source_code)
print(f"Maintainability: {metrics['maintainability_index']['rating']}")
Generate Tests
from scripts.test_generator import TestGenerator
generator = TestGenerator()
tests = generator.generate_tests(refactoring_suggestions)
for test in tests['test_cases']:
print(f"Test: {test['name']}")
Output Format
All modules return structured JSON:
{
"analysis_type": "string",
"smells_detected": number,
"code_quality_score": 0-100,
"severity_breakdown": { "CRITICAL": n, "HIGH": n, ... },
"refactoring_opportunities": number,
"estimated_effort": "string",
"estimated_quality_improvement": number,
"test_cases_generated": number,
"recommendations": ["array of actionable items"],
"metrics": { "complexity": number, "maintainability": number, ... }
}
Severity Levels
| Level |
Meaning |
Impact |
Action |
| CRITICAL |
Major security/correctness issue |
High risk |
Fix immediately |
| HIGH |
Significant code quality issue |
Moderate risk |
Fix in this sprint |
| MEDIUM |
Maintainability concern |
Low-moderate risk |
Plan refactoring |
| LOW |
Minor improvement opportunity |
Low risk |
Consider for future |
Version & Support
- Version: 1.0.0
- Released: February 8, 2026
- Status: Production Ready
- Confidence: 90%
Future Enhancements (v1.1.0)
- TypeScript and JavaScript support
- Machine learning-based pattern detection
- Historical complexity tracking
- Custom rule engine
- IDE plugin integration
- Automated refactoring execution
- Performance profiling integration
1---2name: code-refactoring-advisor3description: Enterprise code refactoring advisor that detects code smells, anti-patterns, and complexity issues with specific refactoring recommendations, test generation, and maintainability metrics4---5capabilities:6 - python code smell detection (god functions, long parameters, deep nesting, etc.)7 - solidity smart contract anti-patterns (reentrancy, unchecked arithmetic, etc.)8 - cyclomatic complexity calculation per function9 - maintainability index scoring (0-100)10 - specific refactoring recommendations with code examples11 - automatic unit test generation12 - security pattern detection13 - test strategy planning14 - code quality metrics and reporting1516security_considerations:17 - Read-only code analysis (no code execution)18 - No external file access19 - Pattern-based detection only20 - Safe AST parsing with error handling21 - No sensitive data exposure22 - No code modification without user confirmation23 - Sandbox analysis environment2425## Overview2627The **Code Refactoring Advisor** is an enterprise-grade code quality tool that analyzes Python and Solidity code to detect smells, anti-patterns, and complexity issues with actionable refactoring recommendations. It combines pattern detection, complexity metrics, and test generation to improve code quality systematically.2829Key capabilities:30- **Code Smell Detection**: 12+ patterns (god functions, long parameters, deep nesting, etc.)31- **Complexity Analysis**: Cyclomatic complexity and maintainability index calculation32- **Refactoring Recommendations**: Specific solutions with code examples and effort estimates33- **Test Generation**: Automatic unit and integration test case generation34- **Security Patterns**: Solidity vulnerability detection (reentrancy, arithmetic, etc.)3536## Module Details3738### Module 1: Pattern Detector (92% Confidence)39Detects code smells and anti-patterns in Python and Solidity:40- **Python**: God functions, long parameter lists, deep nesting, bare excepts, global variables, magic numbers41- **Solidity**: Reentrancy vulnerabilities, unbounded loops, unchecked arithmetic, unclear visibility42- Outputs: Severity levels (CRITICAL/HIGH/MEDIUM/LOW), confidence scores, line numbers4344### Module 2: Refactoring Suggester (88% Confidence)45Generates specific refactoring solutions:46- Pattern-based recommendations (extract method, parameter object, strategy pattern, etc.)47- Effort estimates (TRIVIAL to LARGE)48- Benefits per refactoring (testability, maintainability, security, etc.)49- Code examples showing before/after5051### Module 3: Complexity Analyzer (90% Confidence)52Calculates code metrics:53- Cyclomatic complexity per function54- Maintainability Index (0-100)55- Code statistics (lines, comments, ratio)56- Health scoring and improvement recommendations5758### Module 4: Test Generator (85% Confidence)59Creates test cases for refactored code:60- Unit tests (extracted methods, parameters, guards)61- Integration tests (combined functionality)62- Security tests (reentrancy, edge cases)63- Test templates and strategies6465## Usage Examples6667### Detect Code Smells68```python69from scripts.pattern_detector import PatternDetector7071detector = PatternDetector()72result = detector.analyze_code(source_code, language="python")73print(f"Smells found: {result['smells_detected']}")74print(f"Code quality: {result['code_quality']}%")75```7677### Get Refactoring Recommendations78```python79from scripts.refactoring_suggester import RefactoringSuggester8081suggester = RefactoringSuggester()82suggestions = suggester.suggest_refactoring(smell_data)83for suggestion in suggestions['suggestions']:84 print(f"{suggestion['smell_type']}: {suggestion['solutions']}")85```8687### Analyze Complexity88```python89from scripts.complexity_analyzer import ComplexityAnalyzer9091analyzer = ComplexityAnalyzer()92metrics = analyzer.analyze_module(source_code)93print(f"Maintainability: {metrics['maintainability_index']['rating']}")94```9596### Generate Tests97```python98from scripts.test_generator import TestGenerator99100generator = TestGenerator()101tests = generator.generate_tests(refactoring_suggestions)102for test in tests['test_cases']:103 print(f"Test: {test['name']}")104```105106## Output Format107108All modules return structured JSON:109110```json111{112 "analysis_type": "string",113 "smells_detected": number,114 "code_quality_score": 0-100,115 "severity_breakdown": { "CRITICAL": n, "HIGH": n, ... },116 "refactoring_opportunities": number,117 "estimated_effort": "string",118 "estimated_quality_improvement": number,119 "test_cases_generated": number,120 "recommendations": ["array of actionable items"],121 "metrics": { "complexity": number, "maintainability": number, ... }122}123```124125## Severity Levels126127| Level | Meaning | Impact | Action |128|-------|---------|--------|--------|129| CRITICAL | Major security/correctness issue | High risk | Fix immediately |130| HIGH | Significant code quality issue | Moderate risk | Fix in this sprint |131| MEDIUM | Maintainability concern | Low-moderate risk | Plan refactoring |132| LOW | Minor improvement opportunity | Low risk | Consider for future |133134## Version & Support135136- **Version**: 1.0.0137- **Released**: February 8, 2026138- **Status**: Production Ready139- **Confidence**: 90%140141## Future Enhancements (v1.1.0)142143- TypeScript and JavaScript support144- Machine learning-based pattern detection145- Historical complexity tracking146- Custom rule engine147- IDE plugin integration148- Automated refactoring execution149- Performance profiling integration