-
-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Overview
This issue tracks a staged migration plan to improve RuboCop configuration following the initial setup in PR #193. The goal is to incrementally enhance code quality through small, focused, reviewable PRs.
Context
PR #193 (#193) added initial RuboCop support with:
- Basic RuboCop configuration with extensions (rubocop-rake, rubocop-rspec)
- Rake tasks for linting and newline checking
- Pre-commit hook support
- GitHub Actions CI integration
This issue outlines the next steps to improve the RuboCop configuration systematically.
Guiding Principles
- Small, focused PRs - Each PR should address one category of changes
- Easy to review - Changes should be straightforward to understand and validate
- Incremental improvement - Build on previous work, avoid breaking changes
- Team alignment - Ensure team agrees with style decisions before enforcement
Staged Migration Plan
Stage 1: Enable High-Value, Low-Controversy Cops (Priority: HIGH)
Estimated effort: Small
Risk: Low
Enable cops that catch common bugs and improve code quality with minimal style impact:
Style/RedundantReturn- Remove unnecessary explicit returnsStyle/RedundantSelf- Remove unnecessary self receiversLint/UnreachableCode- Detect unreachable code (potential bugs)Lint/DuplicateMethods- Detect duplicate method definitionsLint/UselessAssignment- Detect variables assigned but never usedPerformance/StringInclude?- UseString#include?instead of regex when possible
Pros:
- Catches actual bugs and performance issues
- Minimal code style debate
- Quick wins for code quality
Cons:
- May require some code changes
- Need to review each auto-fix
Stage 2: Standardize String and Collection Literals (Priority: MEDIUM)
Estimated effort: Small to Medium
Risk: Low
Enforce consistent quote styles and collection syntax:
Style/StringLiterals- Enforce single quotes for non-interpolated stringsStyle/StringLiteralsInInterpolation- Enforce quotes within interpolationStyle/SymbolArray- Use%i[]for symbol arraysStyle/WordArray- Use%w[]for word arraysStyle/HashSyntax- Enforce modern hash syntax (key: value)
Pros:
- Improves consistency across codebase
- Most can be auto-fixed
- Aligns with Ruby community standards
Cons:
- Creates large diffs (but mechanical changes)
- May trigger debates about quote style preference
Stage 3: Enable Layout and Formatting Cops (Priority: MEDIUM)
Estimated effort: Small
Risk: Very Low
Enforce consistent code formatting:
Layout/TrailingWhitespace- Remove trailing whitespaceLayout/EmptyLineAfterGuardClause- Add empty line after guard clausesLayout/SpaceAroundOperators- Consistent spacing around operatorsLayout/LineLength- Set maximum line length (suggest 120)Layout/EmptyLinesAroundClassBody- Consistent empty lines in classesLayout/EmptyLinesAroundModuleBody- Consistent empty lines in modules
Pros:
- Purely formatting, no logic changes
- Almost entirely auto-fixable
- Improves readability
Cons:
- Large diff potential
- May require configuring max line length threshold
Stage 4: RSpec-Specific Improvements (Priority: MEDIUM)
Estimated effort: Medium
Risk: Medium
Enhance test quality and consistency:
RSpec/ExampleLength- Enforce maximum example lengthRSpec/MultipleExpectations- Limit expectations per exampleRSpec/DescribeClass- Ensure describe blocks reference classesRSpec/ContextWording- Enforce "when/with" context namingRSpec/ExpectChange- Prefer block form of expect changeRSpec/LetBeforeExamples- Ensure let declarations before examples
Pros:
- Improves test readability and maintainability
- Encourages better test practices
- Catches common RSpec antipatterns
Cons:
- May require test refactoring (splitting large examples)
- Some rules may be controversial (e.g., multiple expectations)
- Team alignment needed on test style
Stage 5: Naming Conventions (Priority: LOW)
Estimated effort: Small
Risk: Medium
Enforce consistent naming conventions:
Naming/MethodName- Enforce snake_case for methodsNaming/VariableName- Enforce snake_case for variablesNaming/PredicateName- Enforce?suffix for boolean methodsNaming/AccessorMethodName- Enforce get/set naming patterns
Pros:
- Improves code consistency
- Aligns with Ruby conventions
- Some auto-fixable
Cons:
- May require API changes if public methods renamed
- Could be controversial for established naming patterns
- Needs careful review to avoid breaking changes
Stage 6: Metrics and Complexity (Priority: LOW)
Estimated effort: Large
Risk: High
Enable cops that enforce code complexity limits:
Metrics/MethodLength- Limit method lengthMetrics/ClassLength- Limit class lengthMetrics/ModuleLength- Limit module lengthMetrics/CyclomaticComplexity- Limit cyclomatic complexityMetrics/AbcSize- Limit assignment/branch/condition size
Pros:
- Encourages better code design
- Identifies refactoring opportunities
- Reduces code complexity over time
Cons:
- Large refactoring effort required
- Many legitimate exceptions needed
- Team must agree on thresholds
- Not auto-fixable - requires manual refactoring
- May slow down development initially
Recommendation: Consider this stage optional or very long-term. Start with high thresholds and gradually tighten.
Implementation Checklist
For each stage:
- Create feature branch
- Enable cops in
.rubocop.yml - Run
bundle exec rubocop -ato auto-fix - Manually review and adjust auto-fixes
- Run tests to ensure no breakage
- Create PR with clear description of changes
- Get team review and approval
- Merge and monitor CI
Success Metrics
- All stages completed within 6-8 weeks
- No CI breakage from RuboCop changes
- Team adoption of pre-commit hooks
- Reduction in code review comments about style
- Improved code consistency scores
Notes
- Each stage should be a separate PR
- Auto-fix capabilities reduce manual effort significantly
- Team input welcomed on priorities and specific cop configurations
- Can adjust stage order based on team feedback
Related
- PR Add RuboCop linting and newline enforcement #193: Initial RuboCop setup
- Future: Consider adding additional cops as project matures (e.g., rubocop-performance, rubocop-rails if applicable)