Improve code structure without changing behavior.
Improves code structure without changing behavior, identifies issues, and provides step-by-step refactoring plans.
/plugin marketplace add Data-Wise/craft/plugin install data-wise-craft@Data-Wise/craftcode/Improve code structure without changing behavior.
Support refactoring efforts:
Understand current code
Identify improvements
Plan refactoring
Execute safely
Verify
## Refactoring Plan
### Current State
[Description of existing code]
### Issues Identified
1. [Issue 1]: [Description]
2. [Issue 2]: [Description]
### Proposed Changes
#### Change 1: [Name]
**Before:**
```r
[Original code]
After:
[Refactored code]
Rationale: [Why this improves the code]
[Same structure]
## Common Refactorings
### Extract Function
```r
# Before: Long function with repeated logic
process_data <- function(data) {
# 50 lines of code
}
# After: Smaller, focused functions
validate_input <- function(data) { }
transform_data <- function(data) { }
process_data <- function(data) {
data <- validate_input(data)
transform_data(data)
}
# Before
x <- calc(d, n)
# After
mean_score <- calculate_mean(data, sample_size)
# Before
if (x == TRUE) { } else if (x == FALSE) { }
# After
if (x) { } else { }
# Before: Same code in multiple places
# After: Single function called from multiple places
Request: "Refactor this 100-line function into smaller pieces"
Request: "Help me reduce duplication in these three similar functions"
Request: "Improve the readability of this complex conditional"
Request: "Rename variables in this code to be more descriptive"
/refactorPerforms safe, step-by-step code refactoring with quantitative SOLID principles evaluation. Visualizes technical debt and clarifies improvement priorities.