Class: RuboCop::Cop::Chef::ChefModernize::RespondToProvides

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/modernize/respond_to_provides.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
provides :foo if respond_to?(:provides)

# good
provides :foo

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



45
46
47
48
49
# File 'lib/rubocop/cop/chef/modernize/respond_to_provides.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/modernize/respond_to_provides.rb', line 35

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