Sha256: 9e566ba9c4a897da9f2d4a4a54400642ee532b39e2555e45062e4fa556f87c93

Contents?: true

Size: 1018 Bytes

Versions: 6791

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for `raise` or `fail` statements which do not specify an
      # explicit exception class. (This raises a `RuntimeError`. Some projects
      # might prefer to use exception classes which more precisely identify the
      # nature of the error.)
      #
      # @example
      #   # bad
      #   raise 'Error message here'
      #
      #   # good
      #   raise ArgumentError, 'Error message here'
      class ImplicitRuntimeError < Cop
        MSG = 'Use `%<method>s` with an explicit exception class and message,' \
              ' rather than just a message.'.freeze

        def_node_matcher :implicit_runtime_error_raise_or_fail,
                         '(send nil? ${:raise :fail} {str dstr})'

        def on_send(node)
          implicit_runtime_error_raise_or_fail(node) do |method|
            add_offense(node, message: format(MSG, method: method))
          end
        end
      end
    end
  end
end

Version data entries

6,791 entries across 6,785 versions & 25 rubygems

Version Path
rubocop-0.58.0 lib/rubocop/cop/style/implicit_runtime_error.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.57.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.57.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.57.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.56.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.55.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.54.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.53.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.52.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.52.0 lib/rubocop/cop/style/implicit_runtime_error.rb