RubyMine 2017.2 Release Candidate: Quick-fixes for RuboCop

Since the previous major release (v2017.1) RubyMine has displayed RuboCop offenses treating and highlighting them as code inspections, but lacked an ability to autocorrect found code smells. Now we have improved that partial solution by adding proper quick-fixes:

If you press Alt+Enter, RubyMine will suggest a quick-fix for a found error, and auto-correct all errors in the file with RuboCop. So no more jumping to the terminal to fix your code with RuboCop!

By the way, RuboCop inspections and quick-fixes are now also available in scratch files.

Hi Rob;
Currently we don’t have such an opportunity, so in v2017.2 you can only fix all possible RuboCop offenses. But there’s an open discussion on Slack about how to improve that http://slack.rubymine.org/

You can either jump to the discussion and add your comments there, or write the list of offenses that you want/don’t want to auto-correct right here, and I’ll add it to the list.

Below is the quote from my call for discussion about custom RuboCop quick-fixes on Slack:

As you know, the new v2017.2 provides in-editor RuboCop quick-fixes. If you see an offense in the editor (gray-highlighted code) and hit _Alt+Enter_, RubyMine will suggest an auto-correction and fix *all offenses in a file*.
We’d like to provide a way to *auto-correct offenses one by one*. As RuboCop can’t do that, we’ll have to implement this as a new feature in RubyMine. To do that, we need your help to choose the most important offenses that you auto-correct with RuboCop.
*Let’s start a discussion here, and make a list of such RuboCop offenses*.

Appreciate the reply, thank you. Honestly, my biggest complaint is the huge number of “this line has too many characters” I see every day. It’s just distracting. Long code lines are not a problem at my company.

Instead of correcting offenses one by one, maybe Rubymine could allow us to configure which Robocop offenses should be displayed (and corrected). Something similar to the “code style” and “inspection” settings which are currently available. IMO that would be a better approach as different companies have different coding style guidelines so we would be able to customize Rubymine to always behave according to the guidelines we’re currently following. One example is choosing whether we’d like to use single quotes or double quotes with strings that do not contain interpolation.

For now, we can customize Rubocop’s rules by editing “default.yml”, “disabled.yml” and “enabled.yml”. To find the path to these files, type the following in the command prompt: gem contents rubocop | grep “.yml”. This should work in any O.S. with Ruby installed (*nix OSs already have grep and the Ruby Windows Installer installs MinGW, which includes grep). Rails developers might want to change “Rails: Enabled: false” to true in “disabled.yml”.