class RuboCop::Cop::Style::RedundantCurrentDirectoryInPath

Checks for uses a redundant current directory in path.

@example

# bad
require_relative './path/to/feature'

# good
require_relative 'path/to/feature'

Constants

CURRENT_DIRECTORY_PATH
MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/style/redundant_current_directory_in_path.rb, line 24
def on_send(node)
  return unless (first_argument = node.first_argument)
  return unless first_argument.str_content&.start_with?(CURRENT_DIRECTORY_PATH)
  return unless (index = first_argument.source.index(CURRENT_DIRECTORY_PATH))

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

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