Class: RuboCop::Cop::Chef::Modernize::UseRequireRelative
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/modernize/use_require_relative.rb
Overview
Instead of using require with a File.expand_path and __FILE__ use the simpler require_relative method.
Constant Summary collapse
- MSG =
'Instead of using require with a File.expand_path and __FILE__ use the simpler require_relative method.'
- RESTRICT_ON_SEND =
[:require].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubocop/cop/chef/modernize/use_require_relative.rb', line 46 def on_send(node) (node) do |file, path| return unless path.source == '__FILE__' add_offense(node, severity: :refactor) do |corrector| corrected_value = file.value corrected_value.slice!(%r{^../}) # take the first ../ off the path corrector.replace(node, "require_relative '#{corrected_value}'") end end end |