Sha256: ab96f01ec7e3715a5286a13522cbebfbf4418ca2fda497a6e803e227857cc884

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 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 Kernel
        # This cop checks for the use of `Kernel.catch`.
        #
        # @example
        #
        #   # bad
        #   Kernel.catch
        #
        #   # good
        #   Kernel.cs__catch
        class Catch < Cop
          MSG = 'The use of `catch` is a compatibility risk.'

          def eligible_node? node
            node.method?(:catch)
          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__catch') }
          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/kernel/catch_cop.rb
contrast-agent-3.10.1 resources/rubocops/kernel/catch_cop.rb
contrast-agent-3.10.0 resources/rubocops/kernel/catch_cop.rb
contrast-agent-3.9.1 resources/rubocops/kernel/catch_cop.rb
contrast-agent-3.9.0 resources/rubocops/kernel/catch_cop.rb
contrast-agent-3.8.5 resources/rubocops/kernel/catch_cop.rb
contrast-agent-3.8.4 resources/rubocops/kernel/catch_cop.rb