Sha256: 382e45ece732de01afdea4b8d4220d37185f20c6037af12a48bb761c78cc76f9

Contents?: true

Size: 812 Bytes

Versions: 13

Compression:

Stored size: 812 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Metrics
      # This cop checks that the ABC size of methods is not higher than the
      # configured maximum. The ABC size is based on assignments, branches
      # (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
      class AbcSize < Cop
        include MethodComplexity

        MSG = 'Assignment Branch Condition size for %s is too high. [%.4g/%.4g]'
        BRANCH_NODES = [:send]
        CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES

        private

        def complexity(node)
          a = node.each_node(ASGN_NODES).count
          b = node.each_node(BRANCH_NODES).count
          c = node.each_node(CONDITION_NODES).count
          Math.sqrt(a**2 + b**2 + c**2).round(2)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rubocop-0.34.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.34.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.33.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.32.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.32.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.31.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.30.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.30.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.29.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.29.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.28.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.27.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-0.27.0 lib/rubocop/cop/metrics/abc_size.rb