Integrate Rubocop gem with Popular Ruby Text Editors
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.
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 email@example.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
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.
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.
After the successful installation of the package, when you open/save any file the errors will be displayed in the footer pane.
3. Visual Studio Code
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-rubocopextension and press install. Thats it!
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.
- Place RuboCop Vim file in you Vim’s plugin directory.
- Fire command
:RuboCopand you can see suggestions.
Thanks Piarulli Pierre-Alex for response. Now I have added RuboCop integration to Vim editor as per you recommendation 🙂
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.
Drop us a line to discuss how can we help take your business to the next level.
Choose Your Language
Subscribe to Our Newsletter
- Digital Marketing
- IT Consulting
- Project Management