Class: RuboCop::Cop::Chef::ChefModernize::RespondToResourceName

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb

Overview

Chef 12.5 introduced the resource_name method for resources. Many cookbooks used respond_to?(:resource_name) to provide backwards compatibility with older chef-client releases. This backwards compatibility is no longer necessary.

Examples:


# bad
resource_name :foo if respond_to?(:resource_name)

# good
resource_name :foo

Constant Summary collapse

MSG =
'respond_to?(:resource_name) in resources is no longer necessary in Chef Infra Client 12.5+'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



46
47
48
49
50
# File 'lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb', line 46

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, node.children[1].source)
  end
end

#on_if(node) ⇒ Object



36
37
38
39
40
# File 'lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb', line 36

def on_if(node)
  if_respond_to_resource_name?(node) do
    add_offense(node, location: :expression, message: MSG, severity: :refactor)
  end
end