Class: RuboCop::Cop::Chef::Style::IncludeRecipeWithParentheses
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb
Overview
There is no need to wrap the recipe in parentheses when using the include_recipe helper.
Constant Summary collapse
- MSG =
'There is no need to wrap the recipe in parentheses when using the include_recipe helper'- RESTRICT_ON_SEND =
[:include_recipe].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb', line 42 def on_send(node) include_recipe?(node) do |recipe| return unless node.parenthesized? # avoid chefspec: expect(chef_run).to include_recipe('foo') return if node.parent&.send_type? add_offense(node, severity: :refactor) do |corrector| # keep any receiver, otherwise run_context.include_recipe('foo') would correct to a # bare include_recipe and lose the run_context receiver = node.receiver ? "#{node.receiver.source}." : '' corrector.replace(node, "#{receiver}include_recipe #{recipe.source}") end end end |