Sha256: 86cc5646afc84609a3db64f830de7d5d7379e3b4aaba0435b8fd138744067dbd

Contents?: true

Size: 845 Bytes

Versions: 146

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This module encapsulates the ability to allow certain receivers in a cop.
    module AllowedReceivers
      def allowed_receiver?(receiver)
        receiver_name = receiver_name(receiver)

        allowed_receivers.include?(receiver_name)
      end

      def receiver_name(receiver)
        if receiver.receiver && !receiver.receiver.const_type?
          return receiver_name(receiver.receiver)
        end

        if receiver.send_type?
          if receiver.receiver
            "#{receiver_name(receiver.receiver)}.#{receiver.method_name}"
          else
            receiver.method_name.to_s
          end
        else
          receiver.source
        end
      end

      def allowed_receivers
        cop_config.fetch('AllowedReceivers', [])
      end
    end
  end
end

Version data entries

146 entries across 145 versions & 14 rubygems

Version Path
rubocop-1.71.0 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.70.0 lib/rubocop/cop/mixin/allowed_receivers.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.69.2 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.69.1 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.69.0 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.68.0 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.67.0 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.66.1 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.66.0 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.65.1 lib/rubocop/cop/mixin/allowed_receivers.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.65.0 lib/rubocop/cop/mixin/allowed_receivers.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.64.1 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.63.4 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.63.3 lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.63.2 lib/rubocop/cop/mixin/allowed_receivers.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/mixin/allowed_receivers.rb
rubocop-1.63.1 lib/rubocop/cop/mixin/allowed_receivers.rb