Integration with Other Tools

Speeding up integrations

RuboCop integrates with quite a number of other tools, including editors which may attempt to do autocorrection for you. In these cases, rubocop ends up getting called repeatedly, which may result in some slowness, as rubocop has to require its entire environment on each call.

You can alleviate some of that boot time by using "Server" or rubocop-daemon. rubocop-daemon is a wrapper around rubocop that loads everything into a daemonized process so that subsequent runs save on that boot time after the first execution. Please see the rubocop-daemon documentation for setup instructions and examples of how to use it with some editors and other tools.

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

All popular editors provide some form of linter integration. Typically this is done either via LSP (if supported by the underlying server) or by shelling out to a linter and processing its output so it could be displayed inside the editor.

As noted above, the rubocop binary starts relatively slowly which makes it problematic in the shelling out case. The RuboCop "Server" functionality has designed to address this problem and provide lightning fast editor integration.

LSP

The Language Server Protocol is the modern standard for providing cross-editor support for various programming languages. The RuboCop LSP functionality has designed to provide built-in language server. The following is a LSP client for interacting with the built-in server:

And the following Ruby LSP servers are using RuboCop internally to provide code linting functionality:

Emacs

rubocop.el is a simple Emacs interface for RuboCop. It allows you to run RuboCop inside Emacs and quickly jump between problems in your code.

flycheck > 0.9 also supports RuboCop and uses it by default when available.

Vim

RuboCop is supported by syntastic, neomake, and ale.

There is also the vim-rubocop plugin.

Helix

Helix supports Solargraph natively to provide LSP features. For formatting support, see the External binary formatter configuration for RuboCop to use either your bundled or globally installed version of RuboCop.

Sublime Text

For ST you might find the SublimeLinter-rubocop or the Sublime RuboCop plugin useful.

You may also consider using one of the LSP servers mentioned above which utilize RuboCop by using the Sublime-LSP plugin and follow its documentation for configuration.

Brackets

The brackets-rubocop extension displays RuboCop results in Brackets. It can be installed via the extension manager in Brackets.

TextMate2

The textmate2-rubocop bundle displays formatted RuboCop results in a new window. Installation instructions can be found here.

Atom

The linter-rubocop plugin for Atom’s linter runs RuboCop and highlights the offenses in Atom.

LightTable

The lt-rubocop plugin provides LightTable integration.

RubyMine / Intellij IDEA

RuboCop support is available as of the 2017.1 releases.

Visual Studio Code

The ruby extension provides RuboCop integration for Visual Studio Code. RuboCop is also used for the formatting capabilities of this extension.

Other Editors

Here’s one great opportunity to contribute to RuboCop - implement RuboCop integration for your favorite editor.

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.8.1
  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.8.1
  hooks:
    - id: rubocop
      additional_dependencies:
        - rubocop-rails
        - rubocop-rspec

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