Class: RuboCop::Cop::Chef::ChefDeprecations::WindowsTaskChangeAction

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

Overview

The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+ The default action of :create should can now be used to create an update tasks.

Examples:


# bad
windows_task 'chef ad-join leave start time' do
  task_name 'chef ad-join leave'
  start_day '06/09/2016'
  start_time '01:00'
  action [:change, :create]
end

# good
windows_task 'chef ad-join leave start time' do
  task_name 'chef ad-join leave'
  start_day '06/09/2016'
  start_time '01:00'
  action :create
end

Constant Summary collapse

MSG =
'The :change action in the windows_task resource was removed when windows_task was added to Chef Infra Client 13+. The default action of :create should can now be used to create an update tasks.'.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

#autocorrect(node) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb', line 59

def autocorrect(node)
  if node.parent.send_type? # :change was the only action
    lambda do |corrector|
      corrector.replace(node.loc.expression, ':create')
    end
  # chances are it's [:create, :change] since that's all that makes sense, but double check that theory
  elsif node.parent.child_nodes.count == 2 &&
        node.parent.child_nodes.map(&:value).sort == [:change, :create]
    lambda do |corrector|
      corrector.replace(node.parent.loc.expression, ':create')
    end
  end
end

#on_block(node) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb', line 47

def on_block(node)
  match_property_in_resource?(:windows_task, 'action', node) do |action_node|
    action_values = action_node.arguments.first

    if action_values.sym_type? # there's only a single action given
      check_action(action_values)
    else # it was an array of actions
      action_values.node_parts.each { |action| check_action(action) }
    end
  end
end