Class: Reek::Smells::Attribute

Inherits:
SmellDetector show all
Defined in:
lib/reek/smells/attribute.rb

Overview

A class that publishes a getter or setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

Currently this detector raises a warning for every attr, attr_reader, attr_writer and attr_accessor – including those that are private.

TODO: Eliminate private attributes TODO: Catch attributes declared “by hand”

Constant Summary

Constants inherited from SmellDetector

SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from SmellDetector

#smell_category, #smell_type, #smells_found, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SmellDetector

#config_for, #configure_with, default_smell_category, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_category, smell_type, #value

Constructor Details

This class inherits a constructor from Reek::Smells::SmellDetector

Class Method Details

.contextsObject

:nodoc:


20
21
22
# File 'lib/reek/smells/attribute.rb', line 20

def self.contexts # :nodoc:
  [:class, :module]
end

.default_configObject


24
25
26
# File 'lib/reek/smells/attribute.rb', line 24

def self.default_config
  super.merge(Core::SmellConfiguration::ENABLED_KEY => false)
end

Instance Method Details

#examine_context(ctx) ⇒ Array<SmellWarning>

Checks whether the given class declares any attributes.

Returns:


33
34
35
36
37
38
39
40
41
# File 'lib/reek/smells/attribute.rb', line 33

def examine_context(ctx)
  attributes_in(ctx).map do |attribute, line|
    SmellWarning.new self,
                     context: ctx.full_name,
                     lines: [line],
                     message:  "declares the attribute #{attribute}",
                     parameters: { name: attribute.to_s }
  end
end