Class: RuboCop::Cop::Chef::Deprecations::HWRPWithoutUnifiedTrue

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

Overview

Chef Infra Client 15.3 and later include a new Unified Mode that simplifies the execution of resources by replace the traditional compile and converge phases with a single phase. Unified mode simplifies writing advanced resources and avoids confusing errors that often occur when mixing ruby and Chef Infra resources. Chef Infra Client 17.0 and later will begin warning that ‘unified_mode true` should be set in all resources to validate that they will continue to function in Chef Infra Client 18.0 (April 2022) when Unified Mode becomes the default.

Examples:


### incorrect
 class Chef
   class Resource
     class UlimitRule < Chef::Resource
       provides :ulimit_rule

       property :type, [Symbol, String], required: true
       property :item, [Symbol, String], required: true

       # additional resource code
     end
   end
 end

### correct
 class Chef
   class Resource
     class UlimitRule < Chef::Resource
       provides :ulimit_rule
       unified_mode true

       property :type, [Symbol, String], required: true
       property :item, [Symbol, String], required: true

       # additional resource code
     end
   end
 end

Constant Summary collapse

MSG =
'Set `unified_mode true` in Chef Infra Client 15.3+ HWRP style custom resources to ensure they work correctly in Chef Infra Client 18 (April 2022) when Unified Mode becomes the default.'

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_class(node) ⇒ Object



76
77
78
79
80
81
# File 'lib/rubocop/cop/chef/deprecation/hwrp_without_unified_mode_true.rb', line 76

def on_class(node)
  return if unified_mode?(processed_source.ast)
  HWRP?(node) do |inherit|
    add_offense(inherit, severity: :warning)
  end
end