[ruby] Introduce Rubocop for Static Code Analysis#229
Open
hayat01sh1da wants to merge 3 commits intomasterfrom
Open
[ruby] Introduce Rubocop for Static Code Analysis#229hayat01sh1da wants to merge 3 commits intomasterfrom
hayat01sh1da wants to merge 3 commits intomasterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Why (Purpose)
RuboCop has been introduced across all Ruby and Rails projects to improve reliability and maintainability by enforcing consistent coding standards based on the community-driven Ruby Style Guide. Static code analysis catches style violations, potential bugs, and performance issues early — before code reaches production — reducing review burden and keeping the codebase uniform regardless of contributor.
2. What (Procedures)
2-1. Target Projects
RuboCop was applied to 13 projects across 10 repositories.
2-1-1. Pure Ruby Projects (9 projects)
ruby/ruby/ruby/ruby/ruby/ruby/ruby/ruby/ruby/2-1-2. Rails Projects (4 projects)
ruby-on-rails/ruby-on-rails/restful-api/ruby-on-rails/perfect-ruby-on-rails/ruby-on-rails/e-navigator/2-2. Changes Made
Each repository was branched and committed with 3 semantic commits:
2-2-1. Add RuboCop Gems to Gemfile
Pure Ruby projects — Created
ruby/Gemfilewith:Rails projects (RSpec) — Added to the
:developmentgroup afterbrakeman:Rails projects (Minitest) — Added to the
:developmentgroup afterbrakeman:2-2-2. Add
.rubocop.ymlPure Ruby projects —
ruby/.rubocop.yml:Rails projects (RSpec) —
.rubocop.yml:Rails projects (Minitest) —
.rubocop.yml:2-2-3. Add RuboCop Step to CI Workflow
Pure Ruby projects — Added to
.github/workflows/ruby.yml:Rails projects — Added after the
Run Brakemanstep in each workflow:2-3. Git Operations
ruby/introduce-rubocop-to-appAdd RuboCop gems to GemfileAdd .rubocop.ymlAdd RuboCop step to CI workflow3. How (Operation and Maintenance)
3-1. Local Development
Run RuboCop locally before pushing:
Auto-correct safe violations:
3-2. CI Enforcement
RuboCop runs automatically on every push to
masterand on every pull request via GitHub Actions. A failing RuboCop check will block the workflow, ensuring no style violations reach the default branch.3-3. Updating Rules
NewCops: enableis set so newly added cops from RuboCop upgrades are automatically enabled.To suppress a specific cop for a project, add an override to its
.rubocop.yml:To suppress inline:
3-4. Keeping Dependencies Up to Date
Periodically update RuboCop and its extensions:
4. Pros & Cons
4-1. Pros
rubocop-performanceidentifies inefficient patterns and suggests faster alternativesrubocop-rails/rubocop-rspec/rubocop-minitestenforce framework-specific best practicesrubocop -a4-2. Cons
rubocop --auto-gen-configto generate a TODO file.rubocop.ymlas neededNewCops: enablemay introduce new violations on gem updates; review release notes before updating