Sha256: f2884787518a4e423e1dd6e877aed6ff68b3341baad1bf99db8b2332140b28bf

Contents?: true

Size: 868 Bytes

Versions: 10

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for checking `rescue` nodes.
    module RescueNode
      def modifier_locations
        @modifier_locations ||= processed_source.tokens.select(&:rescue_modifier?).map!(&:pos)
      end

      private

      def rescue_modifier?(node)
        return false unless node.respond_to?(:resbody_type?)

        node.resbody_type? && modifier_locations.include?(node.loc.keyword)
      end

      # @deprecated Use ResbodyNode#exceptions instead
      def rescued_exceptions(resbody)
        warn Rainbow(<<~WARNING).yellow, uplevel: 1
          `rescued_exceptions` is deprecated. Use `ResbodyNode#exceptions` instead.
        WARNING

        rescue_group, = *resbody
        if rescue_group
          rescue_group.values
        else
          []
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.69.2 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.69.1 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.69.0 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.68.0 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.67.0 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.66.1 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.66.0 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.65.1 lib/rubocop/cop/mixin/rescue_node.rb
rubocop-1.65.0 lib/rubocop/cop/mixin/rescue_node.rb