Sha256: 5c03982dedf183a1f6a2f33f8b538d0108aa94a9ee6de4ecfd5eafa7c567ac37

Contents?: true

Size: 933 Bytes

Versions: 7

Compression:

Stored size: 933 Bytes

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module RuboCop
  module Cop
    module Security
      module Module
        # This cop checks for the use of `Module#autoload?`.
        #
        # @example
        #
        #   # bad
        #   Module.autoload?
        #
        #   # good
        #   Module.cs__autoload?
        class Autoload < Cop
          MSG = 'The use of `Module#autoload?` is a compatibility risk.'

          def eligible_node? node
            node.method?(:autoload?)
          end

          def on_send node
            return false unless eligible_node?(node)

            add_offense(node, location: :selector)
          end

          def autocorrect node
            ->(corrector) { corrector.replace(node.loc.selector, 'cs__autoload?') }
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.10.1 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.10.0 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.9.1 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.9.0 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.8.5 resources/rubocops/module/autoload_cop.rb
contrast-agent-3.8.4 resources/rubocops/module/autoload_cop.rb