Class: RuboCop::Cop::Chef::RespondToInMetadata

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

Overview

It is not longer necessary respond_to?(:foo) in metadata. This was used to support new metadata methods in Chef 11 and early versions of Chef 12.

Examples:


# bad
chef_version '>= 13' if respond_to?(:chef_version)

# good
chef_version '>= 13'

Constant Summary collapse

MSG =
'It is no longer necessary to use respond_to? in metadata.rb in Chef 12.15 and later'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



45
46
47
48
49
# File 'lib/rubocop/cop/chef/deprecation/respond_to_metadata.rb', line 45

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

#on_if(node) ⇒ Object



35
36
37
38
39
# File 'lib/rubocop/cop/chef/deprecation/respond_to_metadata.rb', line 35

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