I recently found out about Reek from watching Sandi Metz's talk from RailsConf 2016 (great intro to code smells btw).
Code smell detector for Ruby
Table of Contents
- Overview
- Quickstart
- Example
- Supported Ruby versions
- Fixing Smell Warnings
- Sources
- Code smells
- Configuration
- Usage
- Developing Reek / Contributing
- Output formats
- Working with Rails
- Integrations
- Brothers and sisters
- Contributors
- Additional resources
Overview
Quickstart
Reek is a tool that examines Ruby classes, modules and methods and reports any Code Smells it finds.
For an excellent introduction to Code Smells and Reek check out this blog post or that one. There is also this talk from RubyConfBY (there is also a slide deck if you prefer that).
Install it via rubygems:
gem install reek
and run it like this:
reek [options] [dir_or_source_file]*
Example
Imagine a source file demo.rb
containing:
# Smelly
…I love tools like these, because you can run them and have the computer tell you what code might be problematic. Also:
- works with Ruby 2.3, 2.4, 2.5
- little configuration required for Rails
- easy config in general
- has a thorough README
I haven't used it much yet, and it seems to be a fairly popular gem. Have you heard of it? What are your thoughts on it?
Top comments (7)
I use it on all my work projects in concert with rubocop. I feel that reek and rubocop are complimentary for the most part; where rubocop cares more about style, and reek cares more about how you code. Where they overlap, I disable one or the other. I also use them during CI for static code analysis through the pre-commit framework, here: pre-commit.com
I think there's a bug, it highlighted my entire
~/Work
folder...Looks nice. How does this compare/contrast with other static analysis tools in Ruby?
Reek is quite opinionated because it focuses on code smells. It's going to flag lots of stuff in a big codebase like dev.to's but it doesn't hurt :-D
There are overlaps with Rubocop IIRC
See the list of code smells. You're probably going to disable Uncommunicative Name for a while because usually it's a high frequency violation.
It might help getting to fewer issues on codeclimate 🤞🏾
I haven't done Ruby in a bit but when I do I'll add this for sure next time I use it in a project.
Fun, it can be viewed as an expert to learn from. Thanks for share.
Would you look at that.
I'm currently working on a similar tool for python
Tadaboody / good_smell
A linting/refactoring library for python best practices and lesser-known tricks
Good Smell - it makes your code smell good!
A linting/refactoring library for python best practices and lesser-known tricks
Installing:
Usage:
good_smell warn - Print warnings about smells in the code
Alternativly you can run it through flake8. Smells will be with the code SMLxxx
good_smell fix - Print a fixed version of the code
Supported code smells:
Range(len(sequence))
will be fixed to
Directly nested for loops
to
Developing
Clone the repository and run inside it
This will install the requirements and…
I'll be looking at this for inspiration. Thanks!