Sha256: 2d7a75b23fdc012358ac7671a2f02a8856b852d02b5274c86f0b6aad7da7bc19

Contents?: true

Size: 1.64 KB

Versions: 6843

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Handles the `MinSize` configuration option for array-based cops
    # `Style/SymbolArray` and `Style/WordArray`, which check for use of the
    # relevant percent literal syntax such as `%i[...]` and `%w[...]`
    module ArrayMinSize
      private

      def below_array_length?(node)
        node.values.length < min_size_config
      end

      def min_size_config
        cop_config['MinSize']
      end

      def array_style_detected(style, ary_size)
        cfg = config_to_allow_offenses
        return if cfg['Enabled'] == false

        largest_brackets = largest_brackets_size(style, ary_size)
        smallest_percent = smallest_percent_size(style, ary_size)

        if cfg['EnforcedStyle'] == style.to_s
          # do nothing
        elsif cfg['EnforcedStyle'].nil?
          cfg['EnforcedStyle'] = style.to_s
        elsif smallest_percent <= largest_brackets
          self.config_to_allow_offenses = { 'Enabled' => false }
        else
          cfg['EnforcedStyle'] = 'percent'
          cfg['MinSize'] = largest_brackets + 1
        end
      end

      def largest_brackets_size(style, ary_size)
        self.class.largest_brackets ||= -Float::INFINITY

        if style == :brackets && ary_size > self.class.largest_brackets
          self.class.largest_brackets = ary_size
        end

        self.class.largest_brackets
      end

      def smallest_percent_size(style, ary_size)
        @smallest_percent ||= Float::INFINITY

        if style == :percent && ary_size < @smallest_percent
          @smallest_percent = ary_size
        end

        @smallest_percent
      end
    end
  end
end

Version data entries

6,843 entries across 6,818 versions & 27 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/array_min_size.rb