Code refactorer
Welcome to the skill-jam βοΈπ
npx -y skills add VRIL-LABS/skill-jam --skill code-refactorerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Detects code smells (duplication, long methods, god classes) and applies safe, behavior-preserving refactors. Invoke when asked to refactor, clean up, simplify, reduce complexity, or improve the structure of existing code without changing its behavior.
SKILL.md
5.5 KB, as published. Nobody here has run it
Code Refactorer
Identifies code smells and applies safe, systematic refactoring transformations that improve readability, maintainability, and structure without altering observable behavior.
When to Use
- User asks to "refactor this", "clean up", "simplify", or "reduce complexity"
- Code review flagged high complexity, duplication, or poor structure
- A function exceeds 40β50 lines or has many nested conditionals
- A class has too many responsibilities (god class)
- Duplicated logic exists across multiple files
- Code fails maintainability or complexity static analysis rules
- User wants to prepare code for adding new features safely
Process
-
Identify code smells by scanning the provided code:
- Long Method: function > ~40 lines; extract smaller focused functions
- Duplicate Code: identical or near-identical blocks; extract to shared helper
- Long Parameter List: >4 parameters; group into a config/options object
- God Class: class with >10 public methods or mixed concerns; split by responsibility
- Feature Envy: method accesses another object's data more than its own; move it
- Data Clumps: same 3+ variables always appear together; create a value object
- Switch Statements: large switch/if-else chains on type; consider polymorphism
- Magic Numbers/Strings: unexplained literals; extract as named constants
- Deep Nesting: >3 levels of nesting; apply early return / guard clauses
- Dead Code: unreachable or unused code; remove it
-
Prioritize refactors by impact and safety:
- Start with renames and constant extraction (zero behavior risk)
- Then extract methods/functions (low risk)
- Then restructure classes or move code between modules (higher risk, needs tests)
-
Verify tests exist before structural refactors β if not, note the risk and suggest generating tests first using the
test-generatorskill. -
Apply refactors one at a time, explaining each transformation:
- Name the refactoring pattern (Extract Method, Replace Magic Number, Introduce Guard Clause, etc.)
- Show before/after code
- Explain what improved and why the behavior is preserved
-
Preserve all public interfaces β do not rename public functions, change parameter order, or alter return types unless explicitly requested.
-
Update call sites if a helper is extracted or a parameter is consolidated.
-
Ensure naming is improved in the process β refactoring is also an opportunity to rename cryptic variables to expressive ones.
Output Format
For each refactoring applied:
### Refactor 1: Extract Method β `validateUserInput`
**Smell:** Long Method β `registerUser` was 67 lines and mixed validation,
hashing, and persistence logic.
**Before:**
```ts
async function registerUser(data: any) {
if (!data.email || !data.email.includes('@')) {
throw new Error('Invalid email');
}
if (!data.password || data.password.length < 8) {
throw new Error('Password too short');
}
// ... 50 more lines of hashing + DB logic
}
After:
function validateUserInput(data: UserInput): void {
if (!data.email || !data.email.includes('@')) {
throw new ValidationError('Invalid email');
}
if (!data.password || data.password.length < 8) {
throw new ValidationError('Password must be at least 8 characters');
}
}
async function registerUser(data: UserInput) {
validateUserInput(data);
// ... hashing + DB logic only
}
Why it's safe: validateUserInput is a pure extraction β same conditions,
same exceptions, same outcomes. All existing callers of registerUser are unaffected.
## Examples
### Example Input
```python
def process(data):
if data is not None:
if isinstance(data, list):
if len(data) > 0:
result = []
for item in data:
if item > 0:
result.append(item * 2)
return result
return []
Example Output
# Refactor 1: Introduce Guard Clauses (eliminates deep nesting)
# Refactor 2: Replace loop with list comprehension (idiomatic Python)
def process(data: list | None) -> list:
if not data:
return []
return [item * 2 for item in data if item > 0]
Changes:
- Guard clause replaces nested
if not None / isinstance / len > 0checks - List comprehension replaces the manual loop (functionally identical)
- Type hints added for clarity
- Behavior preserved: returns
[]for None, empty list, or all-negative input
Boundaries
- Do NOT change behavior, return types, or exception semantics during refactoring.
- Do NOT rename public API symbols (exported functions, public class methods) unless the user explicitly requests it.
- Do NOT refactor auto-generated code (migrations, protobuf, gRPC stubs, etc.).
- Do NOT apply refactors that require language features not available in the current target version (e.g., no walrus operator if Python < 3.8).
- Always warn if structural refactors are proposed without an existing test suite.
- Do NOT introduce new dependencies as part of a refactor.
- Limit changes to the provided code scope β do not speculatively refactor other files not shown.
- If a refactor requires understanding cross-file dependencies, request those files before proceeding.