Sha256: 757c63b0f5ec4506e26a02c4ca8404653ea6071a17d4ec4d056938b15b72247a

Contents?: true

Size: 1011 Bytes

Versions: 61

Compression:

Stored size: 1011 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.'

        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

61 entries across 42 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.89.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.88.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.87.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.87.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.86.0 lib/rubocop/cop/style/implicit_runtime_error.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/implicit_runtime_error.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/implicit_runtime_error.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.85.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.85.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.84.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.83.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.82.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.81.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.80.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.80.0 lib/rubocop/cop/style/implicit_runtime_error.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/implicit_runtime_error.rb