Sha256: d5d01a0370c4d50d1bb6c3879f8156fabfcc47dfee522ac6418c82993d0c23d2

Contents?: true

Size: 1.1 KB

Versions: 41

Compression:

Stored size: 1.1 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

        # @!method implicit_runtime_error_raise_or_fail(node)
        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

41 entries across 41 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/implicit_runtime_error.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.29.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.29.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.28.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.28.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.28.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.27.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.26.1 lib/rubocop/cop/style/implicit_runtime_error.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.26.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.25.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.25.0 lib/rubocop/cop/style/implicit_runtime_error.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.24.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.24.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.23.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.22.3 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.22.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-1.22.1 lib/rubocop/cop/style/implicit_runtime_error.rb