Class: RuboCop::Cop::Crystal::RequireRelative
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Crystal::RequireRelative
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/crystal/require_relative.rb
Overview
In ruby, require_relative attempts to load the library relative to the directory of the currently executing file. Crystal does not have require_relative, but it has the same behavior in the form of require ‘./foo’
Constant Summary collapse
- MSG =
'Crystal does not support require_relative.'
- RESTRICT_ON_SEND =
[:require_relative]
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubocop/cop/crystal/require_relative.rb', line 25 def on_send(node) add_offense(node) do |corrector| if node.first_argument.value.start_with?('.', '/') require_value = node.first_argument.value else require_value = "./#{node.first_argument.value}" end corrector.replace(node, "require '#{require_value}'") end end |