Skip to content

Latest commit

 

History

History
145 lines (99 loc) · 5.47 KB

README.md

File metadata and controls

145 lines (99 loc) · 5.47 KB

Reek -- code smell detection for Ruby

Overview

Build Status Gem Version Dependency Status Inline docs

Quickstart

reek is a tool that examines Ruby classes, modules and methods and reports any Code Smells it finds. Install it like this:

gem install reek

and run it like this:

reek [options] [dir_or_source_file]*

Example

Imagine a source file demo.rb containing:

class Dirty
  # This method smells of :reek:NestedIterators but ignores them
  def awful(x, y, offset = 0, log = false)
    puts @screen.title
    @screen = widgets.map {|w| w.each {|key| key += 3}}
    puts @screen.contents
  end
end

Reek will report the following code smells in this file:

$ reek demo.rb
spec/samples/demo/demo.rb -- 6 warnings:
  Dirty has no descriptive comment (IrresponsibleModule)
  Dirty#awful has 4 parameters (LongParameterList)
  Dirty#awful has boolean parameter 'log' (ControlCouple)
  Dirty#awful has the parameter name 'x' (UncommunicativeName)
  Dirty#awful has the parameter name 'y' (UncommunicativeName)
  Dirty#awful has the variable name 'w' (UncommunicativeName)
  Dirty#awful has unused parameter 'log' (UnusedParameters)
  Dirty#awful has unused parameter 'offset' (UnusedParameters)
  Dirty#awful has unused parameter 'x' (UnusedParameters)
  Dirty#awful has unused parameter 'y' (UnusedParameters)

Code smells

reek currently includes checks for some aspects of Control Couple, Data Clump, Feature Envy, Large Class, Long Parameter List, Simulated Polymorphism, Too Many Statements, Uncommunicative Name, Unused Parameters and more. See the Code Smells for up to date details of exactly what reek will check in your code.

Configuration

For a basic overview, run

reek --help

For a summary of those CLI options see Command-Line Options.

Apart from that, reek offers quite a few ways for configuring it:

  • The first thing you probably want to check out are the Basic Smell Options
  • reek is not the police. In case you need to suppress a smell warning for whatever reasons have a look at Smell Suppression
  • Lastly there are a couple of ways to configure reek via Configuration Files

Integration

Besides the obvious

reek [options] [dir_or_source_file]*

there are quite a few other ways how to use reek in your projects:

Developing reek / Contributing

The first thing you want to do after checking out the source code is to run bundler

bundle install

and then to run the tests:

bundle exec rspec spec/your/file_spec.rb            # Runs all tests in spec/your/file_spec.rb
bundle exec rspec spec/your/file_spec.rb:23         # Runs test in line 23
bundle exec cucumber features/your_file.feature     # Runs all scenarios in your_file.feature
bundle exec cucumber features/your_file.feature:23  # Runs scenario at line 23

Or just run the whole test suite by running

bundle exec rake

From then on continue by following the establish pull request workflow.

If you don't feel like getting your hands dirty with code there a still other ways you can help us:

  • Work on the wiki
  • Open up an issue and report bugs or suggest other improvements

Output formats

reek supports 3 output formats:

  • plain text (default)
  • html (-H, --html)
  • yaml (-y, --yaml)

Additional resources

Tools

There's a vim plugin for reek: https://github.com/rainerborene/vim-reek

TextMate Bundle for reek: https://github.com/peeyush1234/reek.tmbundle

Colorful output for reek: Preek (also with Guard::Preek)

Find out more: