Class: RuboCop::Cop::Chef::ChefDeprecations::ChefHandlerUsesSupports

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

Overview

Use the type property instead of the deprecated supports property in the chef_handler resource. The supports property was removed in chef_handler cookbook version 3.0 (June 2017) and Chef Infra Client 14.0.

Examples:


# bad
chef_handler 'whatever' do
  supports start: true, report: true, exception: true
end0

# good
chef_handler 'whatever' do
  type start: true, report: true, exception: true
end

Constant Summary collapse

MSG =
'Use the type property instead of the deprecated supports property in the chef_handler resource. The supports property was removed in chef_handler cookbook version 3.0 (June 2017) and Chef Infra Client 14.0.'.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



47
48
49
50
51
# File 'lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb', line 47

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, "type #{node.arguments.first.source}")
  end
end

#on_block(node) ⇒ Object



41
42
43
44
45
# File 'lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb', line 41

def on_block(node)
  match_property_in_resource?('chef_handler', 'supports', node) do |prop_node|
    add_offense(prop_node, location: :expression, message: MSG, severity: :refactor)
  end
end