class RuboCop::Cop::Style::RedundantCurrentDirectoryInPath
require_relative ‘path/to/feature’
# good
require_relative ‘./path/to/feature’
# bad
@example
the current directory (‘./`), which can be omitted.
Checks for paths given to `require_relative` that start with
def on_send(node)
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
def redundant_path_length(path)
def redundant_path_length(path) return unless (match = path&.match(REDUNDANT_CURRENT_DIRECTORY_PREFIX)) match[0].length end