Sha256: 97484b5d7dce22ef73bcc2ba4e5c9d8a71d2611cd2e1a07106d1d72b447f6028

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

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
        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, :expression, "Use `#{method}` with an explicit " \
                                           'exception class and message, ' \
                                           'rather than just a message.')
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.49.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.49.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.48.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.48.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.47.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.47.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.46.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.45.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.44.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.44.0 lib/rubocop/cop/style/implicit_runtime_error.rb