Class: RuboCop::Cop::Chef::Deprecations::ChefRewind
- Extended by:
- AutoCorrector, TargetChefVersion
- Includes:
- RangeHelp, RuboCop::Chef::CookbookHelpers
- Defined in:
- lib/rubocop/cop/chef/deprecation/chef_rewind.rb
Overview
Use ‘delete_resource` or `edit_resource` helpers introduced in Chef Infra Client 12.10 instead of functionality in the deprecated `chef-rewind` gem
Constant Summary collapse
- MAPPING =
{ rewind: 'edit_resource', unwind: 'delete_resource', }.freeze
- MSG =
'Use delete_resource or edit_resource helpers introduced in Chef Infra Client 12.10 instead of functionality in the deprecated chef-rewind gem'
- RESTRICT_ON_SEND =
[:chef_gem, :require, :rewind, :unwind].freeze
Instance Method Summary collapse
Methods included from TargetChefVersion
minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?
Methods included from RuboCop::Chef::CookbookHelpers
#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string
Methods inherited from Base
Instance Method Details
#on_block(node) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/rubocop/cop/chef/deprecation/chef_rewind.rb', line 86 def on_block(node) match_property_in_resource?(:chef_gem, 'package_name', node) do |pkg_name| next unless pkg_name.arguments&.first&.str_content == 'chef-rewind' add_offense(node, severity: :warning) do |corrector| corrector.remove(node) if pkg_name.arguments&.first&.str_content == 'chef-rewind' end end end |
#on_send(node) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubocop/cop/chef/deprecation/chef_rewind.rb', line 65 def on_send(node) rewind_gem_install?(node) do add_offense(node, severity: :warning) do |corrector| node = node.parent if node.parent&.block_type? # make sure we get the whole block not just the method in the block corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left)) end end require_rewind?(node) do add_offense(node, severity: :warning) do |corrector| corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left)) end end rewind_resources?(node) do |string| add_offense(node, severity: :warning) do |corrector| corrector.replace(node, node.source.gsub(string.to_s, MAPPING[string])) end end end |