Sha256: cc76c96c3f30859045d2a5f7b013a4965e55693b6ab7d26c0e73543f3fcb85b2
Contents?: true
Size: 1.09 KB
Versions: 14
Compression:
Stored size: 1.09 KB
Contents
# encoding: utf-8 # frozen_string_literal: true 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]'.freeze BRANCH_NODES = [:send].freeze CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze private def complexity(node) assignment = 0 branch = 0 condition = 0 node.each_node do |child| if child.assignment? assignment += 1 elsif BRANCH_NODES.include?(child.type) branch += 1 elsif CONDITION_NODES.include?(child.type) condition += 1 end end Math.sqrt(assignment**2 + branch**2 + condition**2).round(2) end end end end end
Version data entries
14 entries across 14 versions & 2 rubygems