Class: RuboCop::Cop::Chef::Modernize::PowershellInstallPackage

Inherits:
Base
  • Object
show all
Extended by:
TargetChefVersion
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/modernize/powershell_install_package.rb

Overview

Use the powershell_package resource built into Chef Infra Client instead of the powershell_script resource to run Install-Package

### correct
powershell_package 'docker'

Examples:


### incorrect
powershell_script 'Expand website' do
  code 'Install-Package -Name docker'
end

Constant Summary collapse

MSG =
'Use the powershell_package resource built into Chef Infra Client 12.16+ instead of using Install-Package in a powershell_script resource'

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

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rubocop/cop/chef/modernize/powershell_install_package.rb', line 42

def on_block(node)
  match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
    property_data = method_arg_ast_to_string(code_property)
    return unless property_data && property_data.match?(/^install-package\s/i)
    add_offense(node, severity: :refactor)
  end
end