Class: RuboCop::Cop::Facter::RequireRelative

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/facter/require_relative.rb

Overview

Check that custom facts do no use require_relative, as many Puppet deployments may be using a version of Ruby that doesn’t support it. require_relative was introduced in Ruby 1.9.3, but many Puppet installations still use 1.8.7, as this is the default version supplied with RHEL 6

Examples:

# bad
require_relative 'helpers/custom_fact_helper'

# good
require 'helpers/custom_fact_helper'

Constant Summary collapse

MSG =

rubocop:disable Metrics/LineLength

'Avoid use of `require_relative` as it is not supported in Ruby 1.8.7, still used in many Puppet deployments'.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

rubocop:enable Metrics/LineLength



20
21
22
23
24
# File 'lib/rubocop/cop/facter/require_relative.rb', line 20

def on_send(node)
  _receiver, method_name, *args = *node

  add_offense(node, :selector) if (method_name == :require_relative && _receiver == nil)
end