Sha256: b95e75c1c3313a121fa4dfcfee3cae531746450a2af8f80581fa882e1213ce44

Contents?: true

Size: 960 Bytes

Versions: 12

Compression:

Stored size: 960 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  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 = {}) #:nodoc:
          super()
          @threshold         = options[:threshold] || DEFAULT_THRESHOLD
          @interesting_nodes = [:defn, :iter, :defs]
        end

        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

    end

  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/checks/parameter_number_check.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/checks/parameter_number_check.rb
excellent-1.5.4 lib/simplabs/excellent/checks/parameter_number_check.rb