Skip to content

Instantly share code, notes, and snippets.

@astux7
Last active April 8, 2016 13:59
Show Gist options
  • Save astux7/d36394e0656a7f2c7affa6c96cc221b2 to your computer and use it in GitHub Desktop.
Save astux7/d36394e0656a7f2c7affa6c96cc221b2 to your computer and use it in GitHub Desktop.
Reek common offences

DuplicateMethodCall

https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

example:

def double_thing()
  @other.thing + @other.thing
end

fix:

def double_thing()
  thing = @other.thing
  thing + thing
end

UtilityFunction

https://github.com/troessner/reek/blob/master/docs/Utility-Function.md A Utility Function is any instance method that has no dependency on the state of the instance.

example:

class UtilityFunction
  def showcase(argument)
    argument.to_s + argument.to_i
  end
end

fix: move to diff file cause it does not belongs to this class.

TooManyStatements

Any method that has a large number of lines.

So the following method would score +6 in Reek's statement-counting algorithm:

def parse(arg, argv, &error)
  if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
    return nil, block, nil                                         # +1
  end
  opt = (val = parse_arg(val, &error))[1]                          # +2
  val = conv_arg(*val)                                             # +3
  if opt and !arg
    argv.shift                                                     # +4
  else
    val[0] = nil                                                   # +5
  end
  val                                                              # +6
end

fix: decide with team which number fits to you and add specific configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment