Sha256: 037853d7555cc2f074c4e6aa670c05f9ab3aa94be9dae925d957be073ef4ba9d

Contents?: true

Size: 1.04 KB

Versions: 30

Compression:

Stored size: 1.04 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 < Base
        MSG = 'Use `%<method>s` with an explicit exception class and message,' \
              ' rather than just a message.'
        RESTRICT_ON_SEND = %i[raise fail].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

30 entries across 30 versions & 2 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.10.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.9.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.9.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.8.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.8.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.7.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.6.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.6.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.5.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.5.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.5.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.4.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.4.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.4.0 lib/rubocop/cop/style/implicit_runtime_error.rb