Sha256: 11b79d22d465f059284d0721ba5f4daea88a5296c07efdcb85972e51264f263c

Contents?: true

Size: 975 Bytes

Versions: 7

Compression:

Stored size: 975 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 Object
        # This cop checks for the use of `Object#singleton_class`.
        #
        # @example
        #
        #   # bad
        #   Object.singleton_class
        #
        #   # good
        #   Object.cs__singleton_class
        class SingletonClass < Cop
          MSG = 'The use of `Object#singleton_class` is a compatibility risk.'

          def eligible_node? node
            node.method?(:singleton_class)
          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__singleton_class') }
          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/object/singleton_class_cop.rb
contrast-agent-3.10.1 resources/rubocops/object/singleton_class_cop.rb
contrast-agent-3.10.0 resources/rubocops/object/singleton_class_cop.rb
contrast-agent-3.9.1 resources/rubocops/object/singleton_class_cop.rb
contrast-agent-3.9.0 resources/rubocops/object/singleton_class_cop.rb
contrast-agent-3.8.5 resources/rubocops/object/singleton_class_cop.rb
contrast-agent-3.8.4 resources/rubocops/object/singleton_class_cop.rb