pm-codesmells
Skill2 starsChanged 8 months agoMITView on GitHub
Scan the codebase for common code smells using threshold-based detection: long methods, god classes, long parameter lists, deep nesting, magic numbers, data clumps, and more. Produces a prioritized overview and proposes PinkRooster issues for confirmed findings. Faster and more systematic than pm-audit — uses quantitative metrics rather than exploratory analysis. Use this skill whenever the user says "code smells", "find smells", "check for code smells", "method too long", "god class", "refactoring opportunities", "what needs refactoring", "code quality metrics", "complexity check", or wants a quick structural health scan of their code without a full audit.
In this repository15 other files it gives its agents.
- pm-auditSkill
- pm-brainstormSkill
- pm-cleanupSkill
- pm-doneSkill
- pm-exploreSkill
- pm-housekeepingSkill
- pm-implementSkill
- pm-nextSkill
- pm-planSkill
- pm-refine-frSkill
- pm-scaffoldSkill
- pm-statusSkill
- pm-triageSkill
- pm-troubleshootSkill
- pm-verifySkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 13 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 34
Default: entire src/ directory (skips tests, docs, configs).
- Very specific: line 54
Call mcp__pinkrooster__get_project_status with projectPath set to the directory above
- Distinctive: line 63
Run these detection passes in parallel where possible.
- Very specific: line 83
Use Serena's mcp__serena__get_symbols_overview on each large file (from Pass 1) to get method-level line counts.
- Distinctive: line 95
Search for function/method signatures with many parameters:
- Distinctive: line 110
Search for deeply indented code, which indicates nested conditionals, loops, or callbacks:
- Very specific: line 125
Use Serena's mcp__serena__get_symbols_overview with depth: 1 on files identified in Pass 1 as large.
- Distinctive: line 134
Search for hardcoded numeric literals in logic code (not constants, not array indices, not obvious values like 0, 1, -1):
- Distinctive: line 144
Test files (magic numbers in tests are fine)
- Distinctive: line 151
Search for methods with identical names across different service classes, which may indicate duplicated logic that should be consolidated:
- Distinctive: line 243
When multiple smells affect the same class (e.g., God Class + Long Methods within it), consolidate into a single issue that addresses the …
- Distinctive: line 273
Named smells only: Every finding must map to a recognized code smell from the catalog.
- Distinctive: line 276
No subjective assessments — the numbers speak for themselves.
- Distinctive: line 277
Verify before reporting: Read the flagged code for Critical and Major findings to confirm they're genuine.
- Distinctive: line 281
Deduplicate against existing issues: Check PinkRooster before creating.
- Distinctive: line 282
Maximum 8 issues per scan: If more findings exist, report the top 8 by severity and note the remainder.
- Very specific: line 284
Respect scope: Only analyze files within --scope when specified.
- Distinctive: line 285
Skip test files: Test code has different quality standards — long test methods and magic numbers are normal.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code Smell Detection
Systematically scan the codebase for named code smell patterns using quantitative
thresholds and symbolic analysis. Unlike /pm-audit (which runs broad exploratory
agents across quality, security, performance, and architecture), this skill does
fast, targeted detection of specific structural patterns that indicate refactoring
opportunities.
The output is a prioritized list of confirmed code smells with proposed issues. Each smell maps to a well-known refactoring pattern, giving developers clear direction on how to fix it.
Step 0: Parse Arguments
Parse $ARGUMENTS for flags:
--scope <path>: Limit analysis to a directory (e.g.,src/PinkRooster.Api). Default: entiresrc/directory (skips tests, docs, configs).--threshold <level>: Detection sensitivity.strict: Lower thresholds — catches more, may have noisenormal(default): Balanced thresholdsrelaxed: Higher thresholds — only the worst offenders
Threshold Table
| Smell | Strict | Normal | Relaxed |
| Long Method (lines) | >30 | >50 | >80 |
| Large Class (members) | >15 | >25 | >40 |
| Large File (lines) | >300 | >500 | >800 |
| Long Parameter List | >4 | >5 | >7 |
| Deep Nesting (levels) | >3 | >4 | >5 |
| Magic Numbers (per file) | >3 | >5 | >10 |
Step 1: Resolve Project and Check Existing Issues
- Current directory: /home/najgeetsrev/Development/PinkRoosterMcp
- Call
mcp__pinkrooster__get_project_statuswithprojectPathset to the directory above - Extract the
projectId
Load existing issues for deduplication:
mcp__pinkrooster__get_issue_overviewwithprojectIdandstateFilter: "Active"mcp__pinkrooster__get_issue_overviewwithprojectIdandstateFilter: "Inactive"
Step 2: Fast Structural Scan
Run these detection passes in parallel where possible. Each pass targets one smell category using the most efficient tool for that pattern — Grep for textual patterns, Bash for line counts, Serena for symbolic analysis.
The goal of this phase is speed: cast a wide net, then verify in Step 3.
Pass 1: Large Files
Find files exceeding the line threshold. This is the cheapest scan and immediately identifies candidates for deeper analysis.
find {scope} -name '*.cs' -o -name '*.ts' -o -name '*.tsx' | \
xargs wc -l | sort -rn | head -30Flag files above the Large File threshold.
Pass 2: Long Methods / Functions
Use Serena's mcp__serena__get_symbols_overview on each large file (from Pass 1)
to get method-level line counts. For files not flagged as large, do a quick grep
for long method bodies.
For C# files, the symbol overview gives method locations (start/end lines) — compute the span. For TypeScript files, grep for function/arrow function definitions and estimate body length from the next closing brace at the same indent level.
Flag methods exceeding the Long Method threshold.
Pass 3: Long Parameter Lists
Search for function/method signatures with many parameters:
# C# — methods with many params
Grep: pattern='\([^)]*,[^)]*,[^)]*,[^)]*,[^)]*,' glob='*.cs'
# TypeScript — functions/arrow functions with many params
Grep: pattern='\([^)]*,[^)]*,[^)]*,[^)]*,[^)]*,' glob='*.{ts,tsx}'For each match, count the actual comma-separated parameters (the grep is a rough filter — verify the count is above threshold).
Pass 4: Deep Nesting
Search for deeply indented code, which indicates nested conditionals, loops, or callbacks:
# C# — lines with 5+ levels of indentation (20+ spaces or 5+ tabs)
Grep: pattern='^\s{20,}\S' glob='*.cs'
# TypeScript — lines with deep indentation
Grep: pattern='^\s{10,}\S' glob='*.{ts,tsx}'Group consecutive deeply-indented lines to identify the enclosing method.
Pass 5: God Classes (Large Classes)
Use Serena's mcp__serena__get_symbols_overview with depth: 1 on files identified
in Pass 1 as large. Count the number of direct children (methods + properties) of
each class. Flag classes exceeding the Large Class threshold.
Also look for classes with many injected dependencies (constructor parameters >5), which signal a class doing too many things.
Pass 6: Magic Numbers and Strings
Search for hardcoded numeric literals in logic code (not constants, not array indices, not obvious values like 0, 1, -1):
Grep: pattern='[^a-zA-Z0-9_]([\d]{2,})[^a-zA-Z0-9_]' glob='*.cs'Exclude:
- Constant/static readonly declarations (these ARE the named alternative)
- String interpolation index formatting
- Test files (magic numbers in tests are fine)
- Common values: 0, 1, -1, 2, 100, 1000 (often clear in context)
Flag files with more than the threshold number of magic numbers.
Pass 7: Duplicate Method Signatures
Search for methods with identical names across different service classes, which may indicate duplicated logic that should be consolidated:
Grep: pattern='public.*\s(\w+Async?)\(' glob='*.cs' path='src/'Group by method name — if the same method name appears in 3+ files, it's a candidate for extraction into a shared helper.
Step 3: Verify and Classify Findings
Raw scan results will contain false positives. For each candidate finding:
- Read the actual code at the flagged location (use Read tool with offset/limit to read just the relevant section, not the whole file)
- Apply judgment — is this genuinely a code smell, or is the length/complexity justified by the problem being solved? Some methods are legitimately long because they handle a complex mapping or query. Mark these as false positives.
- Classify by smell name using the catalog below
- Assign severity based on how far above threshold the metric is:
- Minor: 1-1.5x threshold (e.g., 55-line method when threshold is 50)
- Major: 1.5-2x threshold (e.g., 80-line method)
- Critical: >2x threshold (e.g., 120-line method)
Code Smell Catalog
| Smell | Detection | Refactoring |
| Long Method | Method body exceeds line threshold | Extract Method, Decompose Conditional |
| God Class | Class has too many members or dependencies | Extract Class, Move Method |
| Large File | File exceeds line threshold | Split into focused modules |
| Long Parameter List | Method has too many parameters | Introduce Parameter Object, Preserve Whole Object |
| Deep Nesting | Code nested beyond threshold | Extract Method, Replace Nested Conditional with Guard Clauses, Early Return |
| Magic Numbers | Hardcoded literals in logic | Extract Constant, Introduce Named Constant |
| Data Clump | Same group of parameters appears in multiple methods | Introduce Parameter Object |
| Duplicate Logic | Same method name/signature across classes | Extract to shared service or helper |
| Feature Envy | Method uses another class's data more than its own | Move Method to the class it envies |
| Primitive Obsession | Methods with many string/int params instead of typed objects | Introduce Value Object |
Step 4: Present Findings
Sort findings by severity (Critical first), then by smell category.
## Code Smell Scan Results
**Scope**: {scope or "src/"}
**Threshold**: {level} ({description})
**Findings**: {count} across {categoryCount} smell categories
**Files scanned**: {fileCount}
### Critical ({count})
| # | Smell | Location | Metric | Threshold | Refactoring |
|---|-------|----------|--------|-----------|-------------|
| 1 | Long Method | `ProjectService.cs:GetNextActionsAsync` | 156 lines | >50 | Extract Method |
### Major ({count})
| # | Smell | Location | Metric | Threshold | Refactoring |
|---|-------|----------|--------|-----------|-------------|
### Minor ({count})
...
### False Positives Excluded ({count})
- `StateCascadeService.PropagateStateUpwardAsync` (172 lines) — complex state machine, legitimate lengthUse AskUserQuestion:
- Question: "Which findings should I create as tracked issues?"
- Header: "Create issues"
- multiSelect: true
- Options:
- "All Critical + Major ({N})" (recommended)
- "All findings ({N})"
- "Let me pick individually"
- "None — just keep the report"
Step 5: Create Issues
For each confirmed finding, call mcp__pinkrooster__create_or_update_issue:
projectIdname:"Code smell: {smell name} in {class/method name}"description: Include the smell name, metric value vs threshold, affected code location, and the recommended refactoring pattern. Reference the original code smell definition so the implementer understands the "why".issueType:TechnicalDebtseverity: Mapped from smell severity (Critical/Major/Minor)priority: Critical→High, Major→Medium, Minor→LowaffectedComponent: Derived from file path
When multiple smells affect the same class (e.g., God Class + Long Methods within it), consolidate into a single issue that addresses the root cause (the God Class) rather than creating separate issues for each method.
Step 6: Report
## Created {count} Issue(s) from Code Smell Scan
| # | Issue ID | Smell | Location | Severity |
|---|----------|-------|----------|----------|
| 1 | {issueId} | {smell} | {location} | {severity} |
### Smell Distribution
- Long Method: {count}
- God Class: {count}
- ...
### Next Steps
- Scaffold a fix: `/pm-scaffold {issueId}`
- Full audit (security, performance, architecture): `/pm-audit`
- Hygiene cleanup (dead code, unused imports): `/pm-cleanup`
- View project status: `/pm-status`Constraints
- Speed over depth: This skill should complete in under 2 minutes for a medium-sized project. Use targeted searches, not full file reads. Only read code sections that were flagged by the scan passes.
- Named smells only: Every finding must map to a recognized code smell from the catalog. Generic complaints ("this code is messy") are not code smells.
- Threshold-based: Findings must cite a specific metric and its threshold. No subjective assessments — the numbers speak for themselves.
- Verify before reporting: Read the flagged code for Critical and Major findings to confirm they're genuine. Pass 2-7 produce candidates, not confirmed smells.
- Consolidate related smells: A God Class with 5 Long Methods is one issue (refactor the class), not 6 separate issues.
- Deduplicate against existing issues: Check PinkRooster before creating.
- Maximum 8 issues per scan: If more findings exist, report the top 8 by severity and note the remainder.
- Respect scope: Only analyze files within
--scopewhen specified. - Skip test files: Test code has different quality standards — long test methods and magic numbers are normal.
- Skip generated files: Migrations, auto-generated code, and vendor files should not be flagged.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

