Sha256: 78a4b92ac7b88a21f1bd7bd53c0fdd1f78a5064fc4f9da674c1f21db3c58559b

Contents?: true

Size: 1.87 KB

Versions: 49

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Metrics
      # 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.
      #
      # Interpreting ABC size:
      #
      # * ``<= 17`` satisfactory
      # * `18..30` unsatisfactory
      # * `>` 30 dangerous
      #
      # 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`, referenced 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 `AllowedMethods` (defaults to `[]`)
      # And `AllowedPatterns` (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

49 entries across 49 versions & 10 rubygems

Version Path
rubocop-1.74.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.73.2 lib/rubocop/cop/metrics/abc_size.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.73.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.73.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.72.2 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.72.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.72.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.71.2 lib/rubocop/cop/metrics/abc_size.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.71.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.71.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.70.0 lib/rubocop/cop/metrics/abc_size.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.69.2 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.69.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.69.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.68.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.67.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.66.1 lib/rubocop/cop/metrics/abc_size.rb