A Ruby on Rails gem that enforces automated code quality checks via Git hooks using Overcommit. It runs RuboCop, Brakeman, Rails Best Practices, and BundleAudit on every commit to catch style, security, and architectural issues before they enter the codebase.
| Tool | Purpose |
|---|---|
| RuboCop | Static code analysis based on the community Ruby style guide |
| Brakeman | Security vulnerability scanner for Rails applications |
| Rails Best Practices | Code metric tool that checks Rails architectural patterns |
| BundleAudit | Checks Gemfile.lock for known vulnerable gem versions (CVEs) |
| Overcommit | Git hook framework that orchestrates all checks on pre-commit |
Additional checks enabled by default:
- AuthorName / AuthorEmail — Ensures commits have valid author metadata
- BrokenSymlinks, CaseConflicts, MergeConflicts — Prevents common Git issues
- TrailingWhitespace — Disabled by default (configurable in
.overcommit.yml)
Optional hooks (disabled by default; add the gem and enable in .overcommit.yml):
- Reek — Code smell detection
- Flay — Code duplication detection
- Fasterer — Performance improvement suggestions
- Ruby >= 3.1.0
- Rails (any recent version)
- Overcommit (add as a peer dependency in your Gemfile)
# Gemfile
gem 'overcommit', '~> 0.30'
gem 'code_quality_check', '~> 0.1.6'The gem includes RuboCop, Brakeman, Rails Best Practices, RuboCop Performance, and Bundler Audit. You only need to add overcommit separately.
bundle installrails generate code_quality_check:installThis generator will:
- Run
bundle exec overcommit --installto set up Overcommit - Create
config/initializers/code_quality_check.rb— Rails initializer that verifies the gem is installed and ensures Overcommit hooks are set up in development/test - Create
.overcommit.yml— Overcommit hook configuration (RuboCop, Brakeman, Rails Best Practices, BundleAudit, etc.) - Create
.rubocop.yml— RuboCop style configuration - Copy pre-commit and post-checkout hook entrypoints to
.git/hooks/
bundle exec overcommit --signThe initializer (config/initializers/code_quality_check.rb) does two things:
-
Checks that the
code_quality_checkgem is installed
If a developer clones the repo and runs the app without having the gem in their bundle, Rails will raise an error at boot with instructions to add the gem to the Gemfile and run the installer. This ensures the team doesn’t silently skip code quality tooling. -
Ensures Overcommit hooks are present (development/test only)
If the.git/hooks/pre-commithook is missing, it runsbundle exec overcommit --installand signs the hooks so pre-commit checks run on the next commit.
Once installed, every git commit triggers the pre-commit hooks. If any check fails, the commit is blocked until issues are fixed.
# Run all Overcommit hooks
bundle exec overcommit --run
# Run individual tools
bundle exec rubocop
bundle exec brakeman --skip-libs -w3
bundle exec rails_best_practices
bundle exec bundle-audit checkHooks run in the developer’s environment, so they can be skipped with:
OVERCOMMIT_DISABLE=1 git commit -m "WIP: bypass checks"To enforce quality even when someone bypasses local hooks, run the same checks in CI (e.g. bundle exec overcommit --run or individual tools) and use branch protection so commits must pass CI before merge.
You can enable/disable hooks and adjust behavior in .overcommit.yml. For example:
PreCommit:
RuboCop:
enabled: true
RailsBestPractices:
enabled: true
Brakeman:
enabled: true
BundleAudit:
enabled: true
TrailingWhitespace:
enabled: falseTo use optional hooks (Reek, Flay, Fasterer), add the gem to your Gemfile and set enabled: true for the corresponding hook in .overcommit.yml.
See Overcommit configuration docs for options.
The installer creates a relaxed .rubocop.yml suitable for many projects. Customize it for your team's style (line length, complexity limits, exclusions, etc.).
To remove code quality checks from your project:
rails generate code_quality_check:uninstallThis will:
- Remove
config/initializers/code_quality_check.rb - Remove
.overcommit.yml - Remove
.rubocop.yml - Run
bundle exec overcommit --uninstall
| File | Purpose |
|---|---|
config/initializers/code_quality_check.rb |
Verifies code_quality_check gem is installed; in development/test, installs Overcommit hooks if .git/hooks/pre-commit is missing |
.overcommit.yml |
Overcommit hook configuration (RuboCop, Brakeman, Rails Best Practices, BundleAudit, etc.) |
.rubocop.yml |
RuboCop style and lint configuration |
.git/hooks/pre-commit |
Git pre-commit hook (Overcommit entrypoint) |
.git/hooks/post-checkout |
Git post-checkout hook (Overcommit entrypoint) |
bin/setupbundle exec rake rubocop
# or
bundle exec rubocopbin/consolebundle exec rake install- Bump the version in
lib/code_quality_check/version.rb - Run
bundle exec rake releaseto create a git tag, push commits, and publish to RubyGems
Bug reports and pull requests are welcome on GitHub.
This gem is available as open source under the terms of the MIT License.