Early Access Program Features

What’s Mining: New Ruby Inspections for Better Code

Hello everyone,

Writing a code that smells isn’t as terrible as it seems to be. But leaving an ugly code without changing it is much worse. Refactoring is one of the bases of development, and Ruby development is not an exception. RubyMine has a very powerful tool that can help a lot with making your code smell good. I’m talking about ‘Code Inspection’ mechanism. We are tuning it all the time and now it’s time for some Ruby code inspection improvements.

The list of ‘bad code’ metrics for Ruby code inspection is based on Ruby style guide and such tools as Roodi, ReekSaikuroFlogFlay e.t.c. Today I’ll show you some examples how different code checks are performed by RubyMine. Lets take a look at some new code inspections coming in RubyMine 4.

Empty rescue block
This check goes from Roodi and allows to find all rescue blocks without any content. You can decide whether to consider comments as a content and also whether to ignore empty catch blocks when the parameter is named ‘_’. The warning is shown directly in a code that can be rewritten immediately with a help of intention actions.

‘Then’ identifier in multi-line if/unless block
According to Syntax section of the Ruby style guide, you should never use ‘then’ for multi-line if/unless blocks. RubyMine reminds you about it.

Naming conventions
If you’re a newcomer to Ruby or develop with many different languages you might not remember all naming conventions by heart. And it can be really annoying to look after all the names in your code. RubyMine follows Naming section of the style guide by default for Ruby code, but you also can set your own pattern and length as a convention for names.

The list of inspection results is also shown at the ‘Code Inspection’ panel.

The full list of checks with short descriptions is placed in the IDE Settings | Inspections section where every check can switched on or off or configured.

Check out the full list of Ruby code inspection checks available in RubyMine.

image description