Sha256: ac566e3b060055ef5b48f4769a28ee6bba60613f0542fe137e6eabeab4e00168

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      # This check reports methods with an ABC metric score that is higher than the threshold. The ABC metric is basically a measure for complexity
      # and is calculated as:
      #
      #  a = number of assignments
      #  b = number of branches
      #  c = number of conditions
      #
      #  score = Math.sqrt(a*a + b*b + c*c)
      #
      # ==== Applies to
      #
      # * methods
      class AbcMetricMethodCheck < Base

        DEFAULT_THRESHOLD = 10

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

        def evaluate(context) #:nodoc:
          unless context.abc_score <= @threshold
            add_warning(context, '{{method}} has abc score of {{score}}.', { :method => context.full_name, :score => context.abc_score })
          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/abc_metric_method_check.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/checks/abc_metric_method_check.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/checks/abc_metric_method_check.rb
excellent-1.5.4 lib/simplabs/excellent/checks/abc_metric_method_check.rb