class Reek::SmellDetectors::TooManyConstants
A Large Class is a class or module that has a large number of instance variables, methods, constants or lines of code.
+TooManyConstants’ reports classes having more than a configurable number of constants.
See {file:docs/Too-Many-Constants.md} for details.
Constants
- DEFAULT_MAX_CONSTANTS
- IGNORED_NODES
- MAX_ALLOWED_CONSTANTS_KEY
-
The name of the config field that sets the maximum number of constants permitted in a class.
Public Class Methods
Source
# File lib/reek/smell_detectors/too_many_constants.rb, line 22 def self.contexts [:class, :module] end
Source
# File lib/reek/smell_detectors/too_many_constants.rb, line 26 def self.default_config super.merge( MAX_ALLOWED_CONSTANTS_KEY => DEFAULT_MAX_CONSTANTS, EXCLUDE_KEY => []) end
Calls superclass method
Reek::SmellDetectors::BaseDetector::default_config
Public Instance Methods
Source
# File lib/reek/smell_detectors/too_many_constants.rb, line 37 def sniff count = context.local_nodes(:casgn).count { |it| !it.defines_module? } return [] if count <= max_allowed_constants build_smell_warning(count) end
Checks klass
for too many constants.
@return [Array<SmellWarning>]
Private Instance Methods
Source
# File lib/reek/smell_detectors/too_many_constants.rb, line 51 def build_smell_warning(count) [smell_warning( lines: [source_line], message: "has #{count} constants", parameters: { count: count })] end
Source
# File lib/reek/smell_detectors/too_many_constants.rb, line 47 def max_allowed_constants value(MAX_ALLOWED_CONSTANTS_KEY, context) end