Class: Reek::SmellDetectors::Attribute
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::Attribute
- Defined in:
- lib/reek/smell_detectors/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.
This detector raises a warning for every public attr_writer
, attr_accessor
, and attr
with the writable flag set to true
.
See Attribute for details.
TODO: Catch attributes declared “by hand”
Constant Summary
Constants inherited from BaseDetector
BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Class Method Summary collapse
-
.contexts ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #attributes_in_context ⇒ Object private
-
#sniff ⇒ Array<SmellWarning>
Checks whether the given class declares any attributes.
Methods inherited from BaseDetector
#config_for, configuration_keys, default_config, descendants, #enabled?, #exception?, #expression, inherited, #initialize, #run, #smell_type, smell_type, #smell_warning, #source_line, to_detector, todo_configuration_for, #value
Constructor Details
This class inherits a constructor from Reek::SmellDetectors::BaseDetector
Class Method Details
.contexts ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/reek/smell_detectors/attribute.rb', line 19 def self.contexts # :nodoc: [:sym] end |
Instance Method Details
#attributes_in_context ⇒ Object (private)
38 39 40 41 42 43 44 45 |
# File 'lib/reek/smell_detectors/attribute.rb', line 38 def attributes_in_context if context.visibility == :public call_node = expression [[call_node.name, call_node.line]] else [] end end |
#sniff ⇒ Array<SmellWarning>
Checks whether the given class declares any attributes.
28 29 30 31 32 33 34 |
# File 'lib/reek/smell_detectors/attribute.rb', line 28 def sniff attributes_in_context.map do |_attribute, line| smell_warning( lines: [line], message: 'is a writable attribute') end end |