rails-cto-static-analysis
The static analysis skill. Runs Reek, Flog, and Flay on changed Ruby files and auto-refactors when issues are found.
What it does
Every .rb change is analyzed by three tools before RuboCop runs. The idea: refactor for structure first, then lint for style.
- Reek detects code smells — long methods, too many instance variables, feature envy, primitive obsession, irresponsible modules, data clumps, and more.
- Flog scores method complexity. The skill enforces a threshold, and any method that scores too high gets refactored (extract method, collapse conditionals, etc).
- Flay finds structural duplication — code that looks different but has the same shape. Duplication above the threshold gets DRYed up.
Unlike RuboCop, these tools don't fix things on their own. When one of them flags an issue, the skill reads the report and applies the refactor by hand — then re-runs the tool to confirm the issue is gone.
When it triggers
- After modifying any
.rbfile — runs as part ofrails-cto-qa - When you mention reek, flog, flay, code smells, complexity, duplication, static analysis, or refactor
Example
You: Refactor this controller action — it's getting long.
Agent: [invokes /rails-cto-static-analysis]
Flog score: 34 (threshold is 25). Reek finds:
- TooManyStatements in #create (12 statements, limit 6)
- FeatureEnvy: `params[:user]` called 5 times
Refactoring:
→ Extract `user_params` method
→ Extract `build_user` to a command object
→ Collapse two conditionals into a guard clause
[applies the refactors]
[re-runs Flog → score 14, passes]
[re-runs Reek → clean]
[hands off to the rest of /rails-cto-qa for linting + tests]