RuboCop enforces the community Ruby Style Guide on your codebase and reports style, layout, and lint issues. It can autocorrect many offenses from the command line or via editor integration.
Overview
RuboCop is a Ruby static code analyzer and formatter. It checks Ruby source against the community Ruby Style Guide and related cop departments covering lint, style, layout, naming, metrics, security, gemspec, bundler, and migration rules.
Running rubocop in a project inspects files without executing them. The tool parses each file into a syntax tree (via Prism or the parser gem for older Ruby targets), walks the tree, and runs configured cops. Corrections rewrite source text and re-parse until stable, enabling rubocop -a for safe fixes and rubocop -A for more aggressive changes; --diff previews patches without writing files.
Behavior is highly configurable through .rubocop.yml, including inheritance, per-cop settings, and rubocop --auto-gen-config to capture existing violations in .rubocoptodo.yml for gradual adoption. An optional rubydex gem enables project-wide indexing for cross-file cops on Ruby 3.2+. Plugins extend checks to Rails, RSpec, Minitest, Capybara, and other ecosystems.
RuboCop supports MRI 2.7+ and JRuby 9.4+ runtimes while analyzing code targeting Ruby 2.0+. It includes a built-in LSP server for editor integration and documents hundreds of individual cops with autocorrect support in many departments.
Key features
- Community Ruby Style Guide enforcement
- Autocorrect with -a and -A flags
- Highly configurable .rubocop.yml
- Incremental todo via auto-gen-config
- Built-in LSP server
- Department-based cop organization
- Official framework plugins
- Optional project-wide rubydex index
Use cases
- Ruby style consistency in teams
- CI lint gates on pull requests
- Gradual cleanup of legacy codebases
- Editor-integrated formatting
- Custom in-house cop extensions