Sha256: 41784ccb5d1312bb27082e96bcb1aa9e2860e9c0959edb8432a1d11db19e40f1

Contents?: true

Size: 1.68 KB

Versions: 31

Compression:

Stored size: 1.68 KB

Contents

# 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
      # and https://en.wikipedia.org/wiki/ABC_Software_Metric.
      #
      # You can have repeated "attributes" calls count as a single "branch".
      # For this purpose, attributes are any method with no argument; no attempt
      # is meant to distinguish actual `attr_reader` from other methods.
      #
      # @example CountRepeatedAttributes: false (default is true)
      #
      #    # `model` and `current_user`, refenced 3 times each,
      #    # are each counted as only 1 branch each if
      #    # `CountRepeatedAttributes` is set to 'false'
      #
      #    def search
      #      @posts = model.active.visible_by(current_user)
      #                .search(params[:q])
      #      @posts = model.some_process(@posts, current_user)
      #      @posts = model.another_process(@posts, current_user)
      #
      #      render 'pages/search/page'
      #    end
      #
      # This cop also takes into account `IgnoredMethods` (defaults to `[]`)
      class AbcSize < Base
        include MethodComplexity

        MSG = 'Assignment Branch Condition size for %<method>s is too high. ' \
              '[%<abc_vector>s %<complexity>.4g/%<max>.4g]'

        private

        def complexity(node)
          Utils::AbcSizeCalculator.calculate(
            node,
            discount_repeated_attributes: !cop_config['CountRepeatedAttributes']
          )
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
rubocop-1.21.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.20.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.19.1 lib/rubocop/cop/metrics/abc_size.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.19.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.18.4 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.18.3 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.18.2 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.18.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.18.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.17.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.16.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.16.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.15.0 lib/rubocop/cop/metrics/abc_size.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.14.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.13.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.12.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.12.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.11.0 lib/rubocop/cop/metrics/abc_size.rb