Sha256: d8bc34638b68d589daecdb019288dfdc9b595aaaa73d6d57a20a3b0b49c94521

Contents?: true

Size: 1.03 KB

Versions: 117

Compression:

Stored size: 1.03 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.'
        CURRENT_DIRECTORY_PATH = './'

        def on_send(node)
          return unless node.method?(:require_relative)
          return unless node.first_argument.str_content&.start_with?(CURRENT_DIRECTORY_PATH)
          return unless (index = node.first_argument.source.index(CURRENT_DIRECTORY_PATH))

          begin_pos = node.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

117 entries across 117 versions & 9 rubygems

Version Path
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.62.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.61.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.60.2 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.60.1 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
rubocop-1.60.0 lib/rubocop/cop/style/redundant_current_directory_in_path.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/redundant_current_directory_in_path.rb