Integration with Other Tools
Speeding up integrations
RuboCop integrates with many other tools, including editors which may call
rubocop repeatedly. Since rubocop has to require its entire environment on
each invocation, this can result in noticeable slowness.
The recommended solution is RuboCop’s built-in Server mode, which keeps a daemonized process running so that subsequent runs avoid the boot time overhead.
| RuboCop’s built-in caching should also be used to ensure that source files that have not been changed are not being re-evaluated unnecessarily. |
Editor integration
RuboCop includes a built-in Language Server Protocol (LSP) server (since 1.53), which is the recommended way to integrate with any editor. LSP provides real-time linting, formatting, and autocorrection as you type.
The following Ruby language servers use RuboCop internally:
-
Ruby LSP — the recommended option for most editors
-
Solargraph — also provides code completion and documentation
Any editor with an LSP client can use either of these. The per-editor sections below cover the recommended setup for each.
For editors that don’t support LSP, RuboCop can also be invoked by shelling out to the
rubocop binary. In that case, use the Server mode to avoid
the startup overhead on each invocation.
Visual Studio Code
Use the Ruby LSP extension. There is also the dedicated vscode-rubocop extension that uses RuboCop’s built-in LSP server directly.
Emacs
Alternative non-LSP options: rubocop.el and flycheck.
Vim / Neovim
Neovim has a built-in LSP client. For Vim, ALE supports both LSP and direct RuboCop invocation.
RubyMine / IntelliJ IDEA
RuboCop support is built-in.
Helix
Helix has built-in LSP support. For formatting, see the Formatter Configurations for RuboCop.
Sublime Text
Use the LSP package. See the LSP documentation for setup.
Alternative non-LSP options: SublimeLinter-rubocop.
Other Editors
Any editor with an LSP client can use RuboCop — see the language servers listed above.
MCP
RuboCop also provides a built-in Model Context Protocol server (since 1.85) for integration with AI-powered tools. See MCP for details.
Git pre-commit hook integration with overcommit
overcommit is a fully configurable and
extendable Git commit hook manager. To use RuboCop with overcommit, add the
following to your .overcommit.yml file:
PreCommit:
RuboCop:
enabled: true
Git pre-commit hook integration with pre-commit
pre-commit is a framework for managing and maintaining
multi-language pre-commit hooks. To use RuboCop with pre-commit, add the
following to your .pre-commit-config.yaml file:
- repo: https://github.com/rubocop/rubocop
rev: v1.85.0
hooks:
- id: rubocop
If your RuboCop configuration uses extensions, be sure to include the gems as
entries in additional_dependencies:
- repo: https://github.com/rubocop/rubocop
rev: v1.85.0
hooks:
- id: rubocop
additional_dependencies:
- rubocop-rails
- rubocop-rspec
RuboCop supports pre-commit hook integration since version 1.9.
Guard integration
If you’re fond of Guard you might like guard-rubocop. It allows you to automatically check Ruby code style with RuboCop when files are modified.
Mega-Linter integration
You can use Mega-Linter to run RuboCop automatically on every PR, and also lint all file types detected in your repository.
Please follow the installation instructions to activate RuboCop without any additional configuration.
Mega-Linter’s Ruby flavor is optimized for Ruby linting.
Rake integration
To use RuboCop in your Rakefile add the following:
require 'rubocop/rake_task'
RuboCop::RakeTask.new
If you run rake -T, the following two RuboCop tasks should show up:
$ rake rubocop # Run RuboCop
$ rake rubocop:autocorrect # Autocorrect RuboCop offenses
The above will use default values.
require 'rubocop/rake_task'
desc 'Run RuboCop on the lib directory'
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ['lib/**/*.rb']
# only show the files with failures
task.formatters = ['files']
# don't abort rake on failure
task.fail_on_error = false
end