RuboCop is a very popular gem among ruby developers for the static code analysis of the ruby codebase. It does static code analysis as per ruby style guide. If you are a beginner in Ruby and Rails, it is highly recommended to use this gem as it will help you a lot to improve your coding skills.

The first thing you need to do is installing the rubocop gem.

$ gem install rubocop

You can always fire rubocop shell command from base directory of your source code to start code analysis but how about your favourite text editors help you to display all the styles which you are violating as you write the code? Seems cool right? So lets integrate RuboCop to few popular text editors.

Benefits of integration

  • Increases code readability
  • Increases efficiency
  • Eases the modification of code

Let start adding this to our favorite code editors.

  1. Sublime
Sublime
Sublime Text Official Logo

Sublime RuboCop is a Sublime Text plugin that runs RuboCop on your ruby files. The main benefit of this integration is it will give you the errors as soon as you open/save any ruby(.rb) file.

NOTE: Make sure you have installed Package Control in your sublime.

You can integrate this gem to your sublime text by following steps –

  • Navigate to sublime text packages folder and run below commands on your console
$ cd ~/.config/sublime-text-3
$ cd Packages
  • Now as you are moved to the sublime text packages directory, execute below command
$ git clone git@github.com:pderichs/sublime_rubocop.git "RuboCop"
  • Now restart your sublime text editor and your integration for sublime is completed!

Now as and when you open/save any ruby file, this plugin will analyze the ruby code and will show you errors if any. The part of code having errors will be underlined red and when you move the cursor to that line the error message will be displayed in the status bar of sublime. See below

sublime status bar

Here you can see following errors/suggestions in this ruby file

  • ‘Missing top-level class documentation comment’ in first line
  • ‘Trailing white space detected’ on line number 11
  • ‘Use less assignment to variable user1 on line 15

Integration of this gem with sublime increases readability of code and makes it more efficient.

2. Atom

atom
Atom Editor Official Logo

Integrating RuboCop to your Atom text editor is very easy. Follow the steps as mentioned below

  • Open the Atom the text editor and navigate to Edit > Preferences
  • Now click on +Install button and search for linter-rubocop package and install it.
install rubocop on atom

After the successful installation of the package, when you open/save any file the errors will be displayed in the footer pane.

atom status bar

3. Visual Studio Code

visual studio
Visual Studio Code Official Logo

Integration RuboCop with Visual Studio Code is again very simple! Follow below steps

  • Open Visual Studio Code Editor
  • Go to Extensions Tab (or press Ctrl + Shift + X)
  • Search for ruby-rubocop extension and press install. Thats it!
install rubocop on visual studio
Ruby Rubocop extension for Visual Studio Code

After successful installation the ruby-rubocop, editor will highlight the error code with wavy underline(green color in below theme), when you take the mouse cursor to that code it will show you suggestions/corrections in your code.

visual studio status bar

4. Vim

vim
Vim Editor Logo

This is super easy in Vim editor with RuboCop Vim plugin.

  • Place RuboCop Vim file in you Vim’s plugin directory.
  • Fire command :RuboCop and you can see suggestions.
vim status bar
Suggestions by RuboCop for Vim Editor

Thanks Piarulli Pierre-Alex for response. Now I have added RuboCop integration to Vim editor as per you recommendation 🙂

5. RubyMine

rubymine
RubyMine Editor Logo

Just follow the steps mentioned in https://github.com/sirlantis/rubocop-for-rubymine#installation.


At BoTree Technologies, we build web and mobile applications to add value to our client’s business. We align ourselves to ensure that our client benefits the most out of our engagement.

We work in Ruby on RailsPython, Java, React, Android, iOS and RPA as well.

Drop us a line to discuss how can we help take your business to the next level.