Class: RuboCop::Cop::Chef::Modernize::ShellOutToChocolatey

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

Overview

Use the Chocolatey resources built into Chef Infra Client instead of shelling out to the choco command

powershell_script 'add artifactory choco source' do
  code "choco source add -n=artifactory -s='https://mycorp.jfrog.io/mycorp/api/nuget/chocolatey-remote' -u foo -p bar"x
  not_if 'choco source list | findstr artifactory'
end

Examples:


### incorrect
execute 'install package foo' do
  command "choco install --source=artifactory \"foo\" -y --no-progress --ignore-package-exit-codes"
end

Constant Summary collapse

MSG =
'Use the Chocolatey resources built into Chef Infra Client instead of shelling out to the choco command'

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



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubocop/cop/chef/modernize/shellouts_to_chocolatey.rb', line 41

def on_block(node)
  match_property_in_resource?(:powershell_script, 'code', node) do |code_property|
    property_data = method_arg_ast_to_string(code_property)
    next unless property_data && property_data.match?(/^choco /i)
    add_offense(node, severity: :refactor)
  end

  match_property_in_resource?(:execute, 'command', node) do |code_property|
    property_data = method_arg_ast_to_string(code_property)
    next unless property_data && property_data.match?(/^choco /i)
    add_offense(node, severity: :refactor)
  end
end