Sha256: a1adc58153c6934a7268368c69848e0904bdbf789fcf6f3bd0192d6e431572a7

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for uses a redundant current directory in path.
      #
      # @example
      #
      #   # bad
      #   require_relative './path/to/feature'
      #
      #   # good
      #   require_relative 'path/to/feature'
      #
      class RedundantCurrentDirectoryInPath < Base
        include RangeHelp
        extend AutoCorrector

        MSG = 'Remove the redundant current directory path.'
        RESTRICT_ON_SEND = %i[require_relative].freeze
        CURRENT_DIRECTORY_PATH = './'

        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
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.67.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.66.1 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.66.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.65.1 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.65.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.64.1 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.63.4 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.63.3 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.63.2 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.63.1 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.63.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb