lib/simplabs/excellent/checks/parameter_number_check.rb in simplabs-excellent-1.0.1 vs lib/simplabs/excellent/checks/parameter_number_check.rb in simplabs-excellent-1.2.1

- old
+ new

@@ -4,28 +4,29 @@ module Excellent module Checks + # 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 class ParameterNumberCheck < Base DEFAULT_THRESHOLD = 3 - def initialize(options = {}) + def initialize(options = {}) #:nodoc: super() - @threshold = options[:threshold] || DEFAULT_THRESHOLD + @threshold = options[:threshold] || DEFAULT_THRESHOLD + @interesting_nodes = [:defn, :iter, :defs] end - def interesting_nodes - [:defn] - end - - def evaluate(node) - method_name = node[1] - parameters = node[2][1..-1] - parameter_count = parameters.inject(0) { |count, each| count = count + (each.class == Symbol ? 1 : 0) } - unless parameter_count <= @threshold - add_error('Method {{method}} has {{parameter_count}} parameters.', { :method => method_name, :parameter_count => parameter_count }) + 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 end