Class: RuboCop::Cop::Chef::Deprecations::ChocolateyPackageUninstallAction

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb

Overview

Use the ‘:remove` action in the `chocolatey_package` resource instead of `:uninstall` which was removed in Chef Infra Client 14+.

Examples:


### incorrect
chocolatey_package 'nginx' do
  action :uninstall
end

### correct
chocolatey_package 'nginx' do
  action :remove
end

Constant Summary collapse

MSG =
'Use the :remove action in the chocolatey_package resource instead of :uninstall which was removed in Chef Infra Client 14+'

Instance Method Summary collapse

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

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rubocop/cop/chef/deprecation/chocolatey_package_uninstall_action.rb', line 42

def on_block(node)
  match_property_in_resource?(:chocolatey_package, 'action', node) do |choco_action|
    choco_action.arguments.each do |action|
      next unless action.source == ':uninstall'
      add_offense(action, severity: :warning) do |corrector|
        corrector.replace(action, ':remove')
      end
    end
  end
end