Class: Roodi::Checks::ParameterNumberCheck
- Defined in:
- lib/roodi/checks/parameter_number_check.rb
Overview
Checks a method to make sure the number of parameters it has is under the specified limit.
A method taking too many parameters is a code smell that indicates it might be doing too much, or that the parameters should be grouped into one or more objects of their own. It probably needs some refactoring.
Constant Summary collapse
- DEFAULT_PARAMETER_COUNT =
5
Constants inherited from Check
Instance Attribute Summary collapse
-
#parameter_count ⇒ Object
Returns the value of attribute parameter_count.
Instance Method Summary collapse
- #evaluate_start(node) ⇒ Object
-
#initialize ⇒ ParameterNumberCheck
constructor
A new instance of ParameterNumberCheck.
- #interesting_nodes ⇒ Object
Methods inherited from Check
#add_error, #end_file, #errors, #evaluate_end, #evaluate_node, #evaluate_node_end, #evaluate_node_start, make, #position, #start_file
Constructor Details
#initialize ⇒ ParameterNumberCheck
Returns a new instance of ParameterNumberCheck.
16 17 18 19 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 16 def initialize super() self.parameter_count = DEFAULT_PARAMETER_COUNT end |
Instance Attribute Details
#parameter_count ⇒ Object
Returns the value of attribute parameter_count.
14 15 16 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 14 def parameter_count @parameter_count end |
Instance Method Details
#evaluate_start(node) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 25 def evaluate_start(node) method_name = node[1] arguments = node[2] actual_parameter_count = arguments.select {|arg| [Sexp, Symbol].include? arg.class}.count - 1 add_error "Method name \"#{method_name}\" has #{actual_parameter_count} parameters. It should have #{@parameter_count} or less." unless actual_parameter_count <= @parameter_count end |
#interesting_nodes ⇒ Object
21 22 23 |
# File 'lib/roodi/checks/parameter_number_check.rb', line 21 def interesting_nodes [:defn] end |