public
Description: Code smell detector for Ruby
Home | Edit | New

Utility Function

A Utility Function is any instance method that has no dependency on the state of the instance.

Current Support in Reek

Currently Utility Function will warn about any method that:

  • is non-empty
  • does not override an inherited method
  • calls at least one method on another object
  • doesn’t use any of self’s instance variables
  • doesn’t use any of self’s methods

Configuration

Reek’s Utility Function detector supports the Basic Smell Options, plus:

Option Value Effect
max_helper_calls integer The maximum number of method calls to other objects allowed within a method. Defaults to 2. Since v1.1.3.16

Earlier versions of the UtilityFunction detector were too strict for some cases. In particular, a simple helper method of the form:


def lookup(key)
  TOKENS[key]
end

would always be reported as a UtilityFunction in early versions of Reek. The option max_helper_calls now (since v1.1.3.16) by default requires a method to make at least two calls out of the current object in order to be considered a UtilityFunction.

Last edited by kevinrutherford, Sat Sep 19 14:11:17 -0700 2009
Home | Edit | New
Versions: