Sha256: a138ab5dadcfcb1eb68d03088b28705d4aa276814cdd486f1c9f61019fd5d294

Contents?: true

Size: 752 Bytes

Versions: 11

Compression:

Stored size: 752 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for RuntimeError as the argument of raise/fail.
      #
      # Currently it checks for code like this:
      #
      # @example
      #
      #   raise RuntimeError, 'message'
      class RedundantException < Cop
        MSG = 'Redundant `RuntimeError` argument can be removed.'

        TARGET_NODE = s(:const, nil, :RuntimeError)

        def on_send(node)
          return unless command?(:raise, node) || command?(:fail, node)

          _receiver, _selector, *args = *node

          return unless args.size == 2

          first_arg, = *args

          add_offense(first_arg, :expression) if first_arg == TARGET_NODE
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/redundant_exception.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.28.0 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.27.1 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.27.0 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.26.1 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.26.0 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.25.0 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.24.1 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.24.0 lib/rubocop/cop/style/redundant_exception.rb
rubocop-0.23.0 lib/rubocop/cop/style/redundant_exception.rb