Class: RuboCop::Cop::Chef::ChefModernize::PowershellScriptExpandArchive

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb

Overview

Use the archive_file resource built into Chef Infra Client 15+ instead of using the powershell_script resource to run Expand-Archive

Examples:


# bad
powershell_script 'Expand website' do
  code 'Expand-Archive "C:\\file.zip" -DestinationPath "C:\\inetpub\\wwwroot\\" -Force'
end

Constant Summary collapse

MSG =
'Use the archive_file resource built into Chef Infra Client 15+ instead of using Expand-Archive in a powershell_script resource'.freeze

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

Instance Method Details

#on_block(node) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rubocop/cop/chef/modernize/powershell_expand_archive.rb', line 36

def on_block(node)
  match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
    property_data = method_arg_ast_to_string(code_property)
    if property_data && property_data.match?(/^expand-archive/i)
      add_offense(node, location: :expression, message: MSG, severity: :refactor)
    end
  end
end