Method: RuboCop::Cop::Style::RedundantCurrentDirectoryInPath#on_send

Defined in:
lib/rubocop/cop/style/redundant_current_directory_in_path.rb

#on_send(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/style/redundant_current_directory_in_path.rb', line 26

def on_send(node)
  return unless (first_argument = node.first_argument)
  return unless (index = first_argument.source.index(CURRENT_DIRECTORY_PREFIX))
  return unless (redundant_length = redundant_path_length(first_argument.str_content))

  begin_pos = first_argument.source_range.begin.begin_pos + index
  end_pos = begin_pos + redundant_length
  range = range_between(begin_pos, end_pos)

  add_offense(range) do |corrector|
    corrector.remove(range)
  end
end