Sha256: dbbbaabea117844dda52348287dcd9eed16c4c945ee2b44d726334cc6714f4f5

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
# 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

7 entries across 7 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/implicit_runtime_error.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.43.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.42.0 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.41.2 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.41.1 lib/rubocop/cop/style/implicit_runtime_error.rb
rubocop-0.41.0 lib/rubocop/cop/style/implicit_runtime_error.rb