class RuboCop::Cop::Lint::ExceptionCall

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/lint/exception_call.rb, line 19
def autocorrect(node)
  _receiver, _method_name, *args = *node

  lambda do |corrector|
    corrector.insert_before(loc(args), ',')
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/lint/exception_call.rb, line 10
def on_send(node)
  receiver, method_name, *args = *node
  return unless [:raise, :fail].include?(method_name)
  return unless check_receiver(receiver)
  return unless check_args(args)

  add_offense(node, loc(args))
end

Private Instance Methods

check_args(args) click to toggle source
# File lib/rubocop/cop/lint/exception_call.rb, line 35
def check_args(args)
  return false unless args.size == 1

  arg = args.first
  return false unless arg.send_type?
  _receiver, method_name, _args = *arg
  return method_name =~ /^[A-Z]/
end
check_receiver(receiver) click to toggle source
# File lib/rubocop/cop/lint/exception_call.rb, line 29
def check_receiver(receiver)
  return true unless receiver
  return true if receiver.const_type? && receiver.const_name == 'Kernel'
  return false
end
loc(args) click to toggle source
# File lib/rubocop/cop/lint/exception_call.rb, line 44
def loc(args)
  arg = args.first
  _receiver, _method_name, inner_args = *arg
  end_pos   = inner_args.loc.begin.begin_pos
  begin_pos = arg.loc.selector.end_pos
  Parser::Source::Range.new(arg.loc.expression.source_buffer, begin_pos, end_pos)
end