Sha256: b002bac8f27b802da74ea7e17e79ed78b9b4859bc3785c6a3e46bc4a126e3026

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

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_contexts = [Parsing::MethodContext, Parsing::SingletonMethodContext, Parsing::BlockContext]
        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

4 entries across 4 versions & 1 rubygems

Version Path
excellent-1.7.2 lib/simplabs/excellent/checks/parameter_number_check.rb
excellent-1.7.1 lib/simplabs/excellent/checks/parameter_number_check.rb
excellent-1.7.0 lib/simplabs/excellent/checks/parameter_number_check.rb
excellent-1.6.0 lib/simplabs/excellent/checks/parameter_number_check.rb