Class/Module Index [+]

Quicksearch

Reek::Smells::UncommunicativeMethodName

An Uncommunicative Name is a name that doesn’t communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what’s going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

Currently UncommunicativeMethodName checks for

Constants

ACCEPT_KEY

The name of the config field that lists the specific names that are to be treated as exceptions; these names will not be reported as uncommunicative.

DEFAULT_ACCEPT_SET
DEFAULT_REJECT_SET
METHOD_NAME_KEY
REJECT_KEY

The name of the config field that lists the regexps of smelly names to be reported.

SMELL_CLASS
SMELL_SUBCLASS

Public Class Methods

default_config() click to toggle source
# File lib/reek/smells/uncommunicative_method_name.rb, line 39
def self.default_config
  super.adopt(
    REJECT_KEY => DEFAULT_REJECT_SET,
    ACCEPT_KEY => DEFAULT_ACCEPT_SET
  )
end
new(source, config = UncommunicativeMethodName.default_config) click to toggle source
# File lib/reek/smells/uncommunicative_method_name.rb, line 50
def initialize(source, config = UncommunicativeMethodName.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(ctx) click to toggle source

Checks the given context for uncommunicative names.

@return [Array<SmellWarning>]

# File lib/reek/smells/uncommunicative_method_name.rb, line 59
def examine_context(ctx)
  @reject_names = value(REJECT_KEY, ctx, DEFAULT_REJECT_SET)
  @accept_names = value(ACCEPT_KEY, ctx, DEFAULT_ACCEPT_SET)
  name = ctx.name
  return [] if @accept_names.include?(ctx.full_name)
  var = name.to_s.gsub(/^[@\*\&]*/, '')
  return [] if @accept_names.include?(var)
  return [] unless @reject_names.detect {|patt| patt === var}
  smell = SmellWarning.new('UncommunicativeName', ctx.full_name, [ctx.exp.line],
    "has the name '#{name}'",
    @source, 'UncommunicativeMethodName', {METHOD_NAME_KEY => name.to_s})
  [smell]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.