Class: RuboCop::Cop::Chef::Correctness::IncorrectLibraryInjection
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb
Overview
Libraries should be injected into the ‘Chef::DSL::Recipe` class and not `Chef::Recipe` or `Chef::Provider` classes directly.
Constant Summary collapse
- MSG =
'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
- RESTRICT_ON_SEND =
[:send, :include].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb', line 61 def on_send(node) legacy_injection?(node) do add_offense(node, severity: :refactor) do |corrector| if node.parent && correct_injection?(node.parent) corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left)) else corrector.replace(node, node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe')) end end end end |