Class: Simplabs::Excellent::Checks::ParameterNumberCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/parameter_number_check.rb

Overview

This check reports method and blocks that have more parameters than the threshold. Methods with long parameter lists are harder to understand and often an indicator for bad design as well.

Applies to

  • methods

  • blocks

Constant Summary collapse

DEFAULT_THRESHOLD =
3

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initialize(options = {}) ⇒ ParameterNumberCheck

:nodoc:



20
21
22
23
24
# File 'lib/simplabs/excellent/checks/parameter_number_check.rb', line 20

def initialize(options = {}) #:nodoc:
  super()
  @threshold         = options[:threshold] || DEFAULT_THRESHOLD
  @interesting_nodes = [:defn, :iter, :defs]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



26
27
28
29
30
# File 'lib/simplabs/excellent/checks/parameter_number_check.rb', line 26

def evaluate(context) #:nodoc:
  unless context.parameters.length <= @threshold
    add_warning(context, '{{method}} has {{parameters}} parameters.', { :method => context.full_name, :parameters => context.parameters.length })
  end
end