123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::FeatureLoader Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/rubocop/feature_loader.rb

Overview

This class handles loading files (a.k.a. features in Ruby) specified by --require command line option and require directive in the config.

Normally, the given string is directly passed to require. If a string beginning with . is given, it is assumed to be relative to the given directory.

If a string containing - is given, it will be used as is, but if we cannot find the file to load, we will replace - with / and try it again as when Bundler loads gems.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.load(config_directory_path:, feature:)

Parameters:

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 20

def load(config_directory_path:, feature:)
  new(config_directory_path: config_directory_path, feature: feature).load
end

Instance Attribute Details

#relative?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 75

def relative?
  @feature.start_with?('.')
end

Instance Method Details

#load

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 32

def load
  # Don't use `::Kernel.require(target)` to prevent the following error:
  # https://github.com/rubocop/rubocop/issues/10893
  require(target)
rescue ::LoadError => e
  raise if e.path != target

  begin
    # Don't use `::Kernel.require(target)` to prevent the following error:
    # https://github.com/rubocop/rubocop/issues/10893
    require(namespaced_target)
  rescue ::LoadError => error_for_namespaced_target
    # NOTE: This wrap is necessary due to JRuby 9.3.4.0 incompatibility:
    # https://github.com/jruby/jruby/issues/7316
    raise LoadError, e if error_for_namespaced_target.path == namespaced_target

    raise error_for_namespaced_target
  end
end

#namespaced_featureString (private)

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 55

def namespaced_feature
  @feature.tr('-', '/')
end

#namespaced_targetString (private)

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 60

def namespaced_target
  if relative?
    relative(namespaced_feature)
  else
    namespaced_feature
  end
end

#relative(feature) ⇒ String (readonly, private)

Parameters:

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 70

def relative(feature)
  ::File.join(@config_directory_path, feature)
end

#seems_cannot_load_such_file_error?(error) ⇒ Boolean (private)

Parameters:

  • error (LoadError)
[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 81

def seems_cannot_load_such_file_error?(error)
  error.path == target
end

#targetString (private)

[ GitHub ]

  
# File 'lib/rubocop/feature_loader.rb', line 86

def target
  if relative?
    relative(@feature)
  else
    @feature
  end
end