sometimes nothin' can be a real cool hand

« Roodi version numbering changes. | Main

Release of Roodi 1.3.0

Listen to this article Listen to this article

I've just released version 1.3.0 of Roodi. It contains two new checks - a CaseMissingElse checks that ensures you have a default path through your case statements, and an AssignmentInConditional check that looks out for things like if foo = 1 which are likely to be mis-typed equality checks. I've also DRY'ed up the code a bit, but the major new feature is the ability to provide your own configuration file.

If a config file is not provided, Roodi now configures itself with via a YAML one that ships inside the gem which looks like this:

AssignmentInConditionalCheck:    { }
CaseMissingElseCheck:            { }
ClassLineCountCheck:             { line_count: 300 }
ClassNameCheck:                  { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
CyclomaticComplexityBlockCheck:  { complexity: 4 }
CyclomaticComplexityMethodCheck: { complexity: 8 }
EmptyRescueBodyCheck:            { }
ForLoopCheck:                    { }
MethodLineCountCheck:            { line_count: 20 }
MethodNameCheck:                 { pattern: !ruby/regexp /^[_a-z<>=\[\]|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/ }
ModuleLineCountCheck:            { line_count: 300 }
ModuleNameCheck:                 { pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/ }
ParameterNumberCheck:            { parameter_count: 5 }

It's basically a list of checks, each with a hash of options for that check. You can take this file as a starting point and remove existing check, add your own custom new checks, or change the default values on some of them. I've intentionally been strict on the values on some of the checks with thresholds, setting high standards that I'd expect to see on my own projects. If you're working through a long list of warnings and want to eliminate some of the noise, or if you decide the thresholds should be different, you can save this in your own config file and use it to configure roodi.

To use your own config file with roodi, pass it in as a value to the -config parameter on the command line like this:

roodi -config=my_roodi_config.yml "rails_app/**/*.rb"

Comments

This is a great tool! I just used it to analyze a large project that I'm part of, and I was able to find a few blanket rescues I had missed. It also flagged some top-heavy methods that I never realized are so ripe for refactoring.

One think I noticed. Some coders like this style of conditionals:

if my_var = some_method(param)
# do something with my_var
end

Assuming some_method returns an object or nil, this logic may actually be what was intended, rather than what AssignmentInConditional reports.

Now, I personally don't like this style of assignment/check, but I've grown used to seeing it in code. I realize that this warning can be turned off in the config, but I'm now thinking bad style is bad style and these assignments should to go ...

Thanks for the feedback. I've seen that style quite a bit too. Roodi tells me that the Rails code base is littered with it for example. I've set the defaults in Roodi to be intentionally opinionated about what I think is bad style, and this is a great example.

First at all, thanks! roodi is an amazing tool!

Second, do you know why roodi report EmptyRescueBody in this code?

~> roodi temp/exc_handler.rb
temp/exc_handler.rb:5 - Rescue block should not be empty.

Found 1 errors.


.

class ExcHandler
def self.ehandler
begin
raise 'A test exception.'
rescue Exception => e
@msg end
end
end

Is it a bug?

Thanks, Gabriel

Marty, first a big thank you!

I'm using the tool for a couple of days now and it is a great help. And when I find something worth using, I also think it's worth giving feed-back, embrace for impact ;)

My cyclometic complexity for methods with case statements is very high, even when I have only 3 or 4 whens. Could it be that roodi is counting enthusiastically in this "case"?

Roodi is not so though on me with if statements. On the contrary, even with ifs with nested elseifs, roodi does not complain. Is roodi missing something here?

I also get the EmptyRescueBodies that Gabriel mentions, btw.

In most of the cases however Roodi is spot on and I am happy that Roodi finds my crappy coding before my colleagues do :) Thanks again.

Marty, first a big thank you!

I'm using the tool for a couple of days now and it is a great help. And when I find something worth using, I also think it's worth giving feed-back, embrace for impact ;)

My cyclometic complexity for methods with case statements is very high, even when I have only 3 or 4 whens. Could it be that roodi is counting enthusiastically in this "case"?

Roodi is not so though on me with if statements. On the contrary, even with ifs with nested elseifs, roodi does not complain. Is roodi missing something here?

I also get the EmptyRescueBodies that Gabriel mentions, btw.

In most of the cases however Roodi is spot on and I am happy that Roodi finds my crappy coding before my colleagues do :) Thanks again.

Post a comment