Class: Reek::SmellDetectors::TooManyInstanceVariables
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::TooManyInstanceVariables
- Defined in:
- lib/reek/smell_detectors/too_many_instance_variables.rb
Overview
A Large Class is a class or module that has a large number of instance variables, methods or lines of code.
+TooManyInstanceVariables’ reports classes having more than a configurable number of instance variables.
See Too-Many-Instance-Variables for details.
Constant Summary collapse
- MAX_ALLOWED_IVARS_KEY =
The name of the config field that sets the maximum number of instance variables permitted in a class.
'max_instance_variables'
- DEFAULT_MAX_IVARS =
4
Constants inherited from BaseDetector
BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Class Method Summary collapse
Instance Method Summary collapse
- #max_allowed_ivars ⇒ Object private
-
#sniff ⇒ Array<SmellWarning>
Checks
klass
for too many instance variables.
Methods inherited from BaseDetector
#config_for, configuration_keys, 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
21 22 23 |
# File 'lib/reek/smell_detectors/too_many_instance_variables.rb', line 21 def self.contexts [:class] end |
.default_config ⇒ Object
25 26 27 28 29 |
# File 'lib/reek/smell_detectors/too_many_instance_variables.rb', line 25 def self.default_config super.merge( MAX_ALLOWED_IVARS_KEY => DEFAULT_MAX_IVARS, EXCLUDE_KEY => []) end |
Instance Method Details
#max_allowed_ivars ⇒ Object (private)
49 50 51 |
# File 'lib/reek/smell_detectors/too_many_instance_variables.rb', line 49 def max_allowed_ivars value(MAX_ALLOWED_IVARS_KEY, context) end |
#sniff ⇒ Array<SmellWarning>
Checks klass
for too many instance variables.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/reek/smell_detectors/too_many_instance_variables.rb', line 36 def sniff variables = context.local_nodes(:ivasgn, [:or_asgn]).map(&:name) count = variables.uniq.size return [] if count <= max_allowed_ivars [smell_warning( lines: [source_line], message: "has at least #{count} instance variables", parameters: { count: count })] end |