sandi-metz-rules

Detect Sandi Metz rule violations in Ruby code and suggest refactorings.

111|5|Updated Oct 29, 2021
One-click install
npx skills add https://github.com/nateberkopec/dotfiles --skill sandi-metz-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sandi-metz-rules
Source: https://github.com/nateberkopec/dotfiles/tree/main/files/home/.claude/skills/sandi-metz-rules
Command: npx skills add https://github.com/nateberkopec/dotfiles --skill sandi-metz-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers ensure their Ruby code adheres to Sandi Metz's maintainability rules, preventing "code smells" and improving object-oriented design. It automates the process of identifying violations and suggesting refactorings, saving manual review time and reducing complexity.

Core Features & Use Cases

  • Automated Code Review: Automatically identifies violations of Sandi Metz's four rules (class/method length, parameter count, controller object instantiation).
  • Refactoring Guidance: Provides concrete, actionable refactoring strategies and code examples for each type of violation, making code easier to understand, test, and maintain.
  • Use Case: A developer submits a Ruby codebase for review. This Skill analyzes the code, flags methods over 5 lines and classes over 100 lines, and suggests specific refactorings like "Extract sub-methods with descriptive names" or "Introduce Parameter Object."

Quick Start

Review the attached Ruby file 'my_service.rb' for Sandi Metz rule violations and suggest refactorings.

Frequently Asked Questions about sandi-metz-rules

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check Ruby code for Sandi Metz rule violations?

Sandi Metz's rules enforce class size under 100 lines, methods under 5 lines, parameters under 4, and single object instantiation in controllers. This Skill automatically scans Ruby codebases to identify violations and flag them for refactoring, helping maintain code quality and object-oriented design.

What are Sandi Metz's four rules for code maintainability?

Sandi Metz's rules limit classes to 100 lines, methods to 5 lines, parameters to 4 per method, and controllers to instantiate only one object. These constraints reduce complexity, improve testability, and encourage better object-oriented design in Ruby applications.

How do I refactor Ruby code that violates these maintainability rules?

This Skill provides concrete refactoring strategies for each violation type: extract sub-methods with descriptive names for long methods, introduce Parameter Objects to reduce parameters, split large classes into focused components, and simplify controller logic. Each suggestion targets the specific rule violation detected.

Can I use this during code reviews for Ruby projects?

Yes. This Skill automates code review by identifying Sandi Metz rule violations in Ruby codebases, saving manual review time. It flags violations and suggests targeted refactorings, making it ideal for refactoring sessions and maintainability assessments.

Does this work with existing Ruby code analysis tools?

This Skill applies Sandi Metz's rules as a focused maintainability analysis for Ruby projects. It complements existing code quality tools by automating detection of these four specific constraints and providing refactoring guidance aligned with object-oriented design principles.

What happens if my Ruby code doesn't meet these rules?

Violations indicate code complexity that may reduce maintainability and testability. This Skill detects violations and recommends concrete refactorings—such as extracting methods, introducing abstractions, or splitting responsibilities—to bring code into compliance with Sandi Metz's guidelines.