class RuboCop::Cop::Chef::Deprecations::ExecuteRelativeCreatesWithoutCwd

In Chef Infra Client 13 and later you must either specific an absolute path when using the `execute` resource's `creates` property or also use the `cwd` property.

@example

#### incorrect
execute 'some_cmd' do
  creates 'something'
end

#### correct
execute 'some_cmd' do
  creates '/tmp/something'
end

execute 'some_cmd' do
  creates 'something'
  cwd '/tmp/'
end

Constants

MSG

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb, line 46
def on_block(node)
  match_property_in_resource?(:execute, 'creates', node) do |offense|
    return unless offense.arguments.count == 1 # we can only analyze simple string args
    return unless offense.arguments.first.str_type? # we can only analyze simple string args

    # skip any creates that are abs paths https://rubular.com/r/3TbDsgcAa1EaIF
    return if offense.arguments.first.value.match?(%r{^(/|[a-zA-Z]:)})

    # return if we have a cwd property
    match_property_in_resource?(:execute, 'cwd', node) do
      return
    end

    add_offense(offense, message: MSG, severity: :warning)
  end
end