Class: ImproveYourCode::SmellDetectors::TooManyConstants

Inherits:
BaseDetector
  • Object
show all
Defined in:
lib/improve_your_code/smell_detectors/too_many_constants.rb

Constant Summary collapse

MAX_ALLOWED_CONSTANTS_KEY =
'max_constants'
DEFAULT_MAX_CONSTANTS =
3
IGNORED_NODES =
%i[module class].freeze

Constants inherited from BaseDetector

BaseDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from BaseDetector

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDetector

configuration_keys, descendants, inherited, #initialize, #run, #smell_type, smell_type, to_detector, todo_configuration_for, valid_detector?

Constructor Details

This class inherits a constructor from ImproveYourCode::SmellDetectors::BaseDetector

Class Method Details

.contextsObject



12
13
14
# File 'lib/improve_your_code/smell_detectors/too_many_constants.rb', line 12

def self.contexts
  %i[class module]
end

.default_configObject



16
17
18
19
20
21
# File 'lib/improve_your_code/smell_detectors/too_many_constants.rb', line 16

def self.default_config
  super.merge(
    MAX_ALLOWED_CONSTANTS_KEY => DEFAULT_MAX_CONSTANTS,
    EXCLUDE_KEY => []
  )
end

Instance Method Details

#sniffObject



23
24
25
26
27
28
29
# File 'lib/improve_your_code/smell_detectors/too_many_constants.rb', line 23

def sniff
  count = constants_count

  return [] if count <= max_allowed_constants

  build_smell_warning(count)
end