Class: ImproveYourCode::SmellDetectors::LongParameterList

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

Constant Summary collapse

MAX_ALLOWED_PARAMS_KEY =
'max_params'

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, contexts, 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

.default_configObject



10
11
12
13
14
15
16
17
# File 'lib/improve_your_code/smell_detectors/long_parameter_list.rb', line 10

def self.default_config
  super.merge(
    MAX_ALLOWED_PARAMS_KEY => 3,
    SmellConfiguration::OVERRIDES_KEY => {
      'initialize' => { MAX_ALLOWED_PARAMS_KEY => 3 }
    }
  )
end

Instance Method Details

#sniffObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/improve_your_code/smell_detectors/long_parameter_list.rb', line 19

def sniff
  count = expression.arg_names.length

  return [] if count <= max_allowed_params

  message = "has #{count} parameters. "\
            "We propose to use Builder Pattern."

  [
    smell_warning(
      context: context,
      lines: [source_line],
      message: message,
      parameters: { count: count }
    )
  ]
end