reek, a code smells detector for ruby
To complement the imminent (ie. sometime next year) publication of the Ruby Refactoring Workbook I’ve been working on a little software tool called ‘reek’. Reek scans ruby code — either source files or in-memory Class objects — looking for some of the code smells discussed in the book. Right now it can detect (certain forms of):
- Long Method
- Large Class
- Feature Envy
- Uncommunicative Name
- Long Parameter List
- Utility Function
- Nested Iterators
As time goes by I’ll be adding checks for more smells, and I hope to make the current checks a bit more sophisticated. But in the agile spirit of going ugly early, the current very early version is available for you to experiment with. To get the tool:
gem install reek
To run it:
reek file1.rb file2.rb ...
If you try it, please let me know what you think and what you’d like the next version to do!
You can browse the reek project’s code repository at http://github.com/kevinrutherford/reek/tree/master or http://rubyforge.org/projects/reek/, both of which are clones of the same Git repository.
Other Ruby tools operating in this same space include Marty Andrews’ Roodi, and flay and flog from the seattle.rb folks. All of these tools have been made possible by the excellent ParseTree gem from the amazingly productive folks at seattle.rb. Looks like Ruby code quality is a hot topic right now, which I think is great news.





Hooray \o/
leethal
September 25, 2008 at 7:14 am
Hi Kevin,
I am looking for help in using Ruby to automate Delphi applications. These client server applications that we are trying to automate is written using Borland Delphi version 5.
Can you provide me some links or documentation for the same. I have a lot of website talk abt using Ruby for WEB based application testing.
Thanks very much
Anuradha
Anuradha
September 28, 2008 at 2:46 pm
[...] were discussing the difficulty of building code smell detectors for Ruby. Since then, Roodi and reek have stepped into the breach. I haven’t tried them yet, but I’ll report back when I [...]
… So We Built One :: Code smell detectors for Ruby
September 29, 2008 at 2:15 pm
Ruby on Rails focused rake task for reek
http://pastie.org/282104
Ingemar
September 30, 2008 at 12:58 pm
@Ingemar:
Great, thanks! A rake task is on my todo list, so thanks for giving me a starter; I’ll bump it up the priority queue and you’ll see it soon.
Kevin Rutherford
September 30, 2008 at 7:39 pm
Hi, kevin.
I’m a beginner to ruby and refactoring and a fan of code analysis tools, so I love reek. Thanks for your contribution!
reek is really helpful for my learning process in both topics. Every smell detected in my code is studied and corrected. But there is a smell that I can’t completely figure out. It’s when reek says:
[Feature Envy] System#to_s uses @rows more than self
I’m always think that @rows is the same as self.rows. Could you explain me this smell?
Thanks, Gabriel
Gabriel Miretti
October 18, 2008 at 3:12 pm
[...] (anti-pattern) in which one code fragment makes more use of another object than it does of itself. reek currently (version 0.2.3) includes a very naive check for Feature Envy: For each method inspected, [...]
reek and feature envy « silk and spinach
October 19, 2008 at 11:04 am
@Gabriel: Check out my latest post reek and feature envy — does it answer your question?
Kevin Rutherford
October 19, 2008 at 11:54 am
Yes, it do. Now, I catch it. Thanks.
Gabriel Miretti
October 19, 2008 at 12:28 pm
It would be good if reek exited with different return code depending on whether there are some smells detected or not.
Adam Byrtek
October 20, 2008 at 1:54 pm
@Adam: Good idea — will do.
Kevin Rutherford
October 20, 2008 at 6:30 pm
Hi!
rubygems.rb:142:in `activate’: can’t activate ParseTree (= 2.1.1, runtime), already activated ParseTree-2.2.0 (Gem::Exception)
I think I have a newer version of ParseTree, should that be a problem? Does this really need version ParseTree version=2.1.1? If yes, maybe the gem spec should install it for me? If not, maybe we need a >= 2.1.1?
Really looking forward to using it!!
Cheers,
Aditya
Aditya Sanghi
October 23, 2008 at 11:17 am
Oh one more thing, does it not run on Windows? After i fixed (read updated) my ZenTest,ParseTree and the RubyInline gems to the latest version i got past the above error.
However now the error is
c:/ruby/lib/ruby/gems/1.8/gems/RubyInline-3.8.0/lib/inline.rb:578:in “’: No such file or directory – cl -nologo -LD -MD -Zi -O2b2xg- -G6 -I c:/ruby/lib/ruby/1.8/i386-mswin32 -I c:/ruby/include -Lc:/ruby/lib -o “c:\\.ruby_inline/Inl
ine_RawParseTree_fa12.so” “c:/.ruby_inline/Inline_RawParseTree_fa12.c” -link /LIBPATH:”c:/ruby/lib” /DEFAULTLIB:”msvcrt-ruby18.lib” /INCREMENTAL:no /EXPORT:Init_Inline_RawParseTree_fa12 (Errno::ENOENT)
Although, I tried it on my ubuntu version and it
worked.
Cheers,
Aditya
Aditya Sanghi
October 23, 2008 at 12:01 pm
@Aditya: Yeah, I get the same thing. I develop on Ubuntu, but it certainly used to work on Windows with earlier versions of ParseTree. I’ll investigate over the weekend, but right now it looks like ParseTree has stopped working on Windows…
Kevin Rutherford
October 23, 2008 at 7:21 pm
[...] reek, a code smells detector for ruby « silk and spinach [...]
เร็วส์ หกสิบหก » นั่งเทียนเขียนข่าว#20
October 26, 2008 at 8:36 am
[...] month, Kevin Rutherford released reek, a “code smells [...]
Ruby Style Guides and Tools: How to Write Good Looking Ruby
October 27, 2008 at 11:43 am
[...] highlights two useful posts about Ruby style (here and here) and includes a link to reek, a popular tool for sniffing out code smells. Read More [...]
ESPN Dev Blog » Blog Archive » Ruby Style Guides and Tools
October 27, 2008 at 4:07 pm
Hey Kevin, this is insanely awesome. I love it. Do you run it on Rails controllers at all? I’m unsure of the seriousness of Feature Envy and Utility Function warnings there. I’m going to look at the code. It might make sense to have wrapper classes which configure or weight the evaluations, e.g., Feature Envy is OK in all controllers, Utility Function is OK in application controller, neither one is OK in a model, etc. I’m kind of undecided as to whether or not it’s a good idea, though. What do you think?
Giles Bowkett
October 27, 2008 at 4:20 pm
Kevin,
Very nice. Much needed!
I’m getting dozens of warnings like:
(string):47: warning: useless use of == in void context
I’m using the latest ParseTree (and probably the latest of the other gems…) on OS X.
Also, it looks like the output doesn’t list the file with the flagged issue.
Dean Wampler
October 28, 2008 at 3:52 pm
@Dean: I often get the same warnings; they usually occur when I accidentally let reek look at rspec files. Try passing a set of files on the command line, or change to a folder where reek can’t see your tests — does that help?
Kevin Rutherford
October 28, 2008 at 4:03 pm
[...] “плохих запахов” для rubyrub http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/ [...]
» Детектор “плохих запа … QAлификация
November 3, 2008 at 7:05 am
hi,
thanx for such a nice tool :) i just forked your code on GitHub. added an interesting feature.
now i can apply my own custom rules in ruby code and configure them over *.reek configuration file. please have a look on it –
http://github.com/teksymmetry/reek/tree/master
i wanted to check more strict variable convention. such as “is_found = …” “can_found = …” or “user_Name = …” kinda variable names will be treated as convention error.
“is/can/has” etc can’t be used in variable name more over no one can mistakenly use upper case in variable name, ie. “useR_name”
best wishes, thnx for nice work.
nhm tanveer hossain khan (hasan)
June 11, 2009 at 10:04 am
@hasan, thanks for taking the time to make a patch! I’ll look at your code soon; in the meantime, I know that Roodi (http://rubyforge.org/projects/roodi/) does some of the same checks — have you seen it?
Kevin Rutherford
June 11, 2009 at 11:37 am