Get the FREE Ultimate OpenClaw Setup Guide →

code-smell-detector

Scanned
npx machina-cli add skill a5c-ai/babysitter/code-smell-detector --openclaw
Files (1)
SKILL.md
3.2 KB

Code Smell Detector Skill

Automated detection of code smells, anti-patterns, and design issues that indicate deeper problems in the codebase. This skill identifies refactoring opportunities and prioritizes them by impact.

Purpose

Enable systematic detection of code smells for:

  • Refactoring prioritization
  • Technical debt identification
  • Code quality improvement
  • Migration preparation
  • Design pattern violations

Capabilities

1. Long Method Detection

  • Identify methods exceeding line thresholds
  • Analyze parameter counts
  • Detect high cyclomatic complexity
  • Suggest extraction candidates

2. Large Class Identification

  • Detect classes with too many responsibilities
  • Identify god classes
  • Analyze class cohesion
  • Suggest decomposition strategies

3. Feature Envy Analysis

  • Find methods using other classes' data excessively
  • Identify misplaced functionality
  • Suggest method relocation
  • Map cross-class dependencies

4. Primitive Obsession Detection

  • Identify overuse of primitives
  • Find missing value objects
  • Detect stringly-typed code
  • Suggest domain type extraction

5. Parallel Inheritance Hierarchy

  • Detect mirrored class hierarchies
  • Identify inheritance coupling
  • Suggest hierarchy consolidation
  • Map inheritance relationships

6. Shotgun Surgery Detection

  • Identify changes requiring multiple file edits
  • Detect scattered functionality
  • Map change propagation patterns
  • Suggest consolidation points

7. God Class Identification

  • Detect classes doing too much
  • Analyze responsibility distribution
  • Calculate lack of cohesion metrics
  • Suggest single responsibility refactoring

Tool Integrations

ToolPurposeIntegration Method
SonarQubeCode smell detectionMCP Server / API
PMDJava smell detectionCLI
IntelliJ IDEAIDE-based analysisCLI / Export
DesigniteDesign smell detectionCLI
ast-grepPattern-based detectionMCP Server / CLI
ESLintJavaScript smell rulesCLI

Output Schema

{
  "analysisId": "string",
  "timestamp": "ISO8601",
  "target": {
    "path": "string",
    "filesAnalyzed": "number"
  },
  "smells": [
    {
      "type": "string",
      "severity": "high|medium|low",
      "file": "string",
      "line": "number",
      "element": "string",
      "description": "string",
      "metrics": {},
      "refactoringSuggestion": "string",
      "estimatedEffort": "string"
    }
  ],
  "summary": {
    "totalSmells": "number",
    "byType": {},
    "bySeverity": {},
    "hotspots": []
  }
}

Integration with Migration Processes

  • code-refactoring: Primary smell identification
  • technical-debt-remediation: Debt quantification
  • legacy-codebase-assessment: Quality assessment

Related Skills

  • static-code-analyzer: Broader quality analysis
  • refactoring-assistant: Smell remediation
  • dead-code-eliminator: Unused code removal

Related Agents

  • code-transformation-executor: Executes refactorings
  • technical-debt-auditor: Prioritizes debt remediation

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/code-migration-modernization/skills/code-smell-detector/SKILL.mdView on GitHub

Overview

Automated detection of code smells, anti-patterns, and design issues across a codebase helps identify refactoring opportunities. It prioritizes remediation by impact to support technical debt reduction, migration preparation, and overall code quality improvement.

How This Skill Works

The detector analyzes source code with pattern- and metric-based checks for long methods, large classes, feature envy, primitive obsession, and more. It outputs a structured list of smells with type, severity, location, and a suggested refactoring, including an estimated effort to guide prioritization.

When to Use It

  • When prioritizing refactors in a legacy codebase to reduce risk before migration
  • During migration or modernization projects to identify design-pattern violations
  • When profiling technical debt hotspots to plan remediation
  • Before delivering major features to ensure code quality and maintainability
  • When onboarding new developers to surface areas requiring refactoring and guidance

Quick Start

  1. Step 1: Run the detector against your target repository using the supported tools (Bash, Read, Write, Grep, Glob, Edit) or via MCP Server / API
  2. Step 2: Review the generated smells array (type, severity, location, description) and the refactoring suggestions
  3. Step 3: Prioritize fixes by impact and estimated effort, then map to a migration plan

Best Practices

  • Prioritize smells by business impact and estimated effort to optimize migration planning
  • Validate findings with multiple tools (e.g., SonarQube, PMD, ESLint) for cross-checking
  • Track hotspots over time and measure improvements after refactoring
  • Map each smell to a concrete refactoring action and responsible owner
  • Document rationale and decisions for traceability in the codebase

Example Use Cases

  • Long Method: a core service method > 200 lines flagged for extraction into smaller methods
  • Large Class: a module with too many responsibilities identified as a god class
  • Feature Envy: a method frequently accessing data from other classes, suggesting relocation
  • Primitive Obsession: stringly-typed data detected where value objects would improve domain clarity
  • Shotgun Surgery: a change requiring edits across many files indicates a consolidation point

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers