Class: RuboCop::Cop::Chef::Deprecations::ResourceInheritsFromCompatResource

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb

Overview

Resources written in the class based HWRP style should inherit from the ‘Chef::Resource’ class and not the ‘ChefCompat::Resource’ class from the deprecated compat_resource cookbook.

Examples:


### incorrect
class AptUpdate < ChefCompat::Resource
  # some resource code
end

### correct
class AptUpdate < Chef::Resource
  # some resource code
end

# better
Write a custom resource using the custom resource DSL and avoid class based HWRPs entirely

Constant Summary collapse

MSG =
"HWRP style resource should inherit from the 'Chef::Resource' class and not the 'ChefCompat::Resource' class from the deprecated compat_resource cookbook."

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_class(node) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb', line 48

def on_class(node)
  inherits_from_compat_resource?(node) do
    add_offense(node, severity: :warning) do |corrector|
      corrector.replace(node, node.source.gsub('ChefCompat', 'Chef'))
    end
  end
end