Sha256: 212acc815e7d730bf782dc8284a620a16093a146b27ec06aca8c6147faf1069a

Contents?: true

Size: 1.8 KB

Versions: 8

Compression:

Stored size: 1.8 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`, 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

8 entries across 8 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/metrics/abc_size.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.32.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.31.2 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.31.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.31.0 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.30.1 lib/rubocop/cop/metrics/abc_size.rb
rubocop-1.30.0 lib/rubocop/cop/metrics/abc_size.rb