| name | fix-rubocop |
| description | Fixes RuboCop offenses systematically and safely. Use when the user wants to reduce RuboCop warnings, clean up .rubocop_todo.yml, fix linting errors, or improve code style compliance. |
| allowed-tools | ["Bash","Read","Edit","Grep"] |
Fix RuboCop Violations Skill
Assists with systematically reducing RuboCop offenses while preserving behavior and keeping changes focused.
IMPORTANT: When using this skill, announce to the user: "Using fix-rubocop skill to fix RuboCop violations systematically."
Goals
- Keep changes minimal and behavior-preserving: Prefer small, focused changes
- Use safe autocorrect first: Apply unsafe corrections only when reviewed and covered by tests
- Centralize rule changes in
.rubocop.yml: Never hand-edit .rubocop_todo.yml
- No inline disables: This project forbids
# rubocop:disable comments
Quick Reference Commands
rake rubocop
bundle exec rubocop path/to/file.rb
bundle exec rubocop -a path/to/file.rb
bundle exec rubocop -A --only Cop/Name path/to/file.rb
rake spec
bundle exec docquet regenerate-todo
Complete Workflow
Step 1: Reproduce and Identify Offenses
rake rubocop
Identify the scope:
- Which cop(s) are failing?
- Which file(s) are affected?
- How many offenses?
Step 2: Safe Autocorrect First
Start with the safest approach - automatic fixes that preserve behavior:
bundle exec rubocop -a lib/foxtail/specific_file.rb
bundle exec rubocop -a lib/foxtail/
rake rubocop
rake spec
If tests fail after autocorrect:
- Revert changes:
git checkout lib/foxtail/specific_file.rb
- Proceed to Step 3 for manual fixes
Step 3: Target Specific Cops (If Still Failing)
For remaining offenses, fix specific cops one at a time:
bundle exec rubocop -A --only Style/StringLiterals lib/foxtail/
bundle exec rubocop --only Performance/MapCompact lib/foxtail/
rake rubocop
rake spec
Important: For logic-sensitive cops (Performance, Lint), prefer manual fixes with test verification.
Step 3a: Fixing Cops Disabled in .rubocop_todo.yml
If a cop is disabled in .rubocop_todo.yml, you must temporarily enable it:
grep -A 5 "Cop/Name" .rubocop_todo.yml
bundle exec rubocop --only Cop/Name path/to/file.rb
bundle exec rubocop -A --only Cop/Name path/to/file.rb
rake rubocop
rake spec
bundle exec docquet regenerate-todo
CRITICAL: Always use docquet regenerate-todo to update the TODO file. Never edit it manually.
Step 4: Update Configuration (Rare)
If a rule conflicts with project style:
Example in .rubocop.yml:
Style/StringLiterals:
EnforcedStyle: double_quotes
After configuration changes:
bundle exec docquet regenerate-todo
rake rubocop
Step 5: No Inline Disables
FORBIDDEN:
def some_method
code_here
end
If a finding cannot be safely fixed:
- Ask the user for guidance
- Options:
- Refine the rule in
.rubocop.yml
- Adjust the code approach
- Document why this specific pattern is needed
Step 6: Validate and Commit
rake
Commit message format:
cat > /tmp/commit_msg.txt <<'EOF'
:police_officer: Fix Style/StringLiterals violations in lib/foxtail
Convert single quotes to double quotes for consistency.
EOF
git commit -F /tmp/commit_msg.txt
rm /tmp/commit_msg.txt
Commit message patterns:
:police_officer: - All RuboCop fixes (style, lint, performance)
:wrench: - Update RuboCop configuration
Common Scenarios
Scenario 1: Reduce .rubocop_todo.yml Violations
cat .rubocop_todo.yml
bundle exec rubocop --only Style/CommentedKeyword
bundle exec rubocop -A --only Style/CommentedKeyword lib/foxtail/
rake spec
rake rubocop
bundle exec docquet regenerate-todo
git add .
git commit -m ":police_officer: Fix Style/CommentedKeyword violations"
Scenario 2: Fix All Offenses in One File
bundle exec rubocop lib/foxtail/date_time_format.rb
bundle exec rubocop -a lib/foxtail/date_time_format.rb
bundle exec rubocop lib/foxtail/date_time_format.rb
bundle exec rubocop -A --only Naming/VariableNumber lib/foxtail/date_time_format.rb
rake spec
bundle exec docquet regenerate-todo
git commit -m ":police_officer: Fix all RuboCop violations in date_time_format.rb"
Scenario 3: Fix Specific Cop Across Entire Codebase
bundle exec rubocop --only Style/StringLiterals
bundle exec rubocop -A --only Style/StringLiterals lib/foxtail/helpers/
rake spec
git add lib/foxtail/helpers/
git commit -m ":police_officer: Fix Style/StringLiterals in helpers"
bundle exec rubocop -A --only Style/StringLiterals lib/foxtail/models/
rake spec
git commit -m ":police_officer: Fix Style/StringLiterals in models"
bundle exec docquet regenerate-todo
git commit -m ":wrench: Regenerate RuboCop TODO after fixes"
Examples by Cop Type
Style Cops (Usually Safe)
bundle exec rubocop -A --only Style/StringLiterals lib/
bundle exec rubocop -A --only Style/HashSyntax lib/
bundle exec rubocop -A --only Style/FrozenStringLiteralComment lib/
Naming Cops (May Need Review)
bundle exec rubocop -A --only Naming/VariableNumber lib/foxtail/file.rb
bundle exec rubocop --only Naming/PredicateMethod lib/foxtail/file.rb
Lint Cops (Require Careful Review)
bundle exec rubocop --only Lint/UnusedMethodArgument lib/
rake spec
Performance Cops (Test Thoroughly)
bundle exec rubocop --only Performance/MapCompact lib/
rake spec
Common Pitfalls to Avoid
- Don't run unsafe autocorrect on entire codebase: Use
-A on small scopes only
- Don't skip test verification: Always run
rake spec after fixes
- Don't manually edit .rubocop_todo.yml: Always use
docquet regenerate-todo
- Don't use inline disables: This project forbids
# rubocop:disable comments
- Don't commit without regenerating TODO: If fixing TODO cops, always regenerate
- Don't mix unrelated fixes: Keep commits focused on one cop or one area
- Don't ignore test failures: Revert and fix manually if tests fail after autocorrect
Troubleshooting
Issue: Cop not showing offenses despite being in .rubocop_todo.yml
Problem: Cop is disabled in TODO file
Solution:
bundle exec rubocop --only Cop/Name
bundle exec docquet regenerate-todo
Issue: Tests fail after autocorrect
Problem: Unsafe autocorrect changed behavior
Solution:
git checkout path/to/file.rb
bundle exec rubocop --only Cop/Name path/to/file.rb
rake spec
Issue: docquet regenerate-todo not working
Problem: Command not found or gem not installed
Solution:
bundle install
bundle exec docquet --version
Issue: Too many offenses to fix at once
Problem: Overwhelming number of violations
Solution:
- Pick ONE cop type to fix
- Start with lowest offense count
- Fix incrementally, one file/directory at a time
- Commit after each successful fix
- Use PR per cop type or per area
PR Guidance
Keep changes small and single-purpose:
- Good: "Fix Style/StringLiterals in lib/foxtail/formatters"
- Bad: "Fix multiple RuboCop issues across codebase"
Include context in PR body:
## Summary
Fix Style/StringLiterals violations in formatter classes
## Changes
- Convert single quotes to double quotes in 5 files
- Applied safe autocorrect (-a flag)
## Verification
- All tests pass (rake spec)
- RuboCop clean for these files
- Regenerated .rubocop_todo.yml
Link rule changes to rationale:
If updating .rubocop.yml, explain why in PR description.
Best Practices
- Start with safe autocorrect: Use
-a before -A
- Small, focused PRs: One cop type or one directory at a time
- Test after every change: Run
rake spec frequently
- Regenerate TODO incrementally: After fixing each cop type
- Commit incrementally: Don't wait to fix everything before committing
- Document decisions: If excluding a cop, explain why in
.rubocop.yml
- Review Performance/Lint changes: Don't blindly autocorrect these
- Keep blast radius small: Target specific files/directories when possible