name: code-smell-detection
description: Use when reviewing code quality, before refactoring, when complexity increases, when code feels "hard to change", during code review, or when onboarding to unfamiliar code - systematic identification of code smells with specific refactoring recipes
Code Smell Detection
Persona: Code quality auditor who catalogs issues without judgment, focusing on objective metrics.
Flagging style preferences as smells (smell != dislike)
Reporting smells without refactoring recipes
Detecting smells in generated or vendored code
Smell Categories
Bloaters (Too Big)
Smell
Detection
Refactoring
Long Method
>20 lines, multiple indents
Extract Method
Large Class
>300 lines, many responsibilities
Extract Class
Long Parameter List
>3 parameters
Introduce Parameter Object
Primitive Obsession
Strings for IDs, ints for money
Value Object
Data Clumps
Same 3+ fields appear together
Extract Class
Change Preventers (Hard to Modify)
Smell
Detection
Refactoring
Divergent Change
One class changed for many reasons
Extract Class per reason
Shotgun Surgery
One change requires many file edits
Move Method, Inline Class
Couplers (Too Connected)
Smell
Detection
Refactoring
Feature Envy
Method uses another class more than own
Move Method
Message Chains
a.b().c().d()
Hide Delegate
Dispensables (Remove)
Smell
Detection
Refactoring
Dead Code
Unreachable, unused
Delete
Duplicate Code
Same logic in multiple places
Extract Method/Class
Comments
Explaining bad code
Refactor code to be clear
Detection
# Long methods/Large files
find ./src -name "*.py" -exec wc -l {} \; | awk '$1 > 300'
# Feature Envy: Count method's references to own vs other class
# If other > own, method belongs elsewhere
Refactoring Recipe: Extract Method
# Before: Long method with comment sections
def process_order(order):
# Validate order
if not order.items: raise ValueError("Empty order")
# Calculate totals
total = sum(item.price for item in order.items) * 1.1
# Notify
send_email(order.customer.email, f"Total: {total}")
# After: Extracted methods
def process_order(order):
validate_order(order)
total = calculate_total(order)
notify_customer(order.customer, total)