class Reek::SmellDetectors::Attribute
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 {file:docs/Attribute.md} for details.
TODO: Catch attributes declared “by hand”
Public Instance Methods
Source
# 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
Checks whether the given class declares any attributes.
@return [Array<SmellWarning>]
Private Instance Methods
Source
# 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