Sha256: 8e3aff13bf2c8b1740e1685ccb53c91416bea97424b27aff17837eb0e668684f

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for *rescue* blocks with no body.
      #
      # @example AllowComments: false (default)
      #
      #   # bad
      #   def some_method
      #     do_something
      #   rescue
      #   end
      #
      #   # bad
      #   def some_method
      #     do_something
      #   rescue
      #     # do nothing
      #   end
      #
      #   # bad
      #   begin
      #     do_something
      #   rescue
      #   end
      #
      #   # bad
      #   begin
      #     do_something
      #   rescue
      #     # do nothing
      #   end
      #
      #   # good
      #   def some_method
      #     do_something
      #   rescue
      #     handle_exception
      #   end
      #
      #   # good
      #   begin
      #     do_something
      #   rescue
      #     handle_exception
      #   end
      #
      # @example AllowComments: true
      #
      #   # bad
      #   def some_method
      #     do_something
      #   rescue
      #   end
      #
      #   # bad
      #   begin
      #     do_something
      #   rescue
      #   end
      #
      #   # good
      #   def some_method
      #     do_something
      #   rescue
      #     # do nothing but comment
      #   end
      #
      #   # good
      #   begin
      #     do_something
      #   rescue
      #     # do nothing but comment
      #   end
      class SuppressedException < Cop
        MSG = 'Do not suppress exceptions.'

        def on_resbody(node)
          return if node.body
          return if cop_config['AllowComments'] && comment_lines?(node)

          add_offense(node)
        end

        private

        def comment_lines?(node)
          processed_source[line_range(node)].any? { |line| comment_line?(line) }
        end
      end
    end
  end
end

Version data entries

9 entries across 8 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/suppressed_exception.rb
rubocop-0.80.1 lib/rubocop/cop/lint/suppressed_exception.rb
rubocop-0.80.0 lib/rubocop/cop/lint/suppressed_exception.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/suppressed_exception.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/suppressed_exception.rb
rubocop-0.79.0 lib/rubocop/cop/lint/suppressed_exception.rb
rubocop-0.78.0 lib/rubocop/cop/lint/suppressed_exception.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/suppressed_exception.rb
rubocop-0.77.0 lib/rubocop/cop/lint/suppressed_exception.rb