class RuboCop::Cop::InternalAffairs::MethodNameEndWith

Checks potentially usage of method identifier predicates defined in rubocop-ast instead of ‘method_name.end_with?`.

@example

# bad
node.method_name.to_s.end_with?('=')

# good
node.assignment_method?

# bad
node.method_name.to_s.end_with?('?')

# good
node.predicate_method?

# bad
node.method_name.to_s.end_with?('!')

# good
node.bang_method?

Constants

MSG
SUGGEST_METHOD_FOR_SUFFIX

Public Instance Methods

on_csend(node)
Alias for: on_send
on_send(node) click to toggle source
# File lib/rubocop/cop/internal_affairs/method_name_end_with.rb, line 52
def on_send(node)
  method_name_end_with?(node) do |method_name_node, end_with_arg|
    range = range(method_name_node, node)
    message = format(
      MSG,
      method_name: SUGGEST_METHOD_FOR_SUFFIX[end_with_arg.value],
      method_suffix: range.source
    )

    add_offense(range, message: message)
  end
end
Also aliased as: on_csend

Private Instance Methods

range(method_name_node, node) click to toggle source
# File lib/rubocop/cop/internal_affairs/method_name_end_with.rb, line 68
def range(method_name_node, node)
  range = if method_name_node.call_type?
            method_name_node.loc.selector
          else
            method_name_node.source_range
          end

  range_between(range.begin_pos, node.source_range.end_pos)
end