class RuboCop::Cop::Chef::Deprecations::ResourceWithoutUnifiedTrue

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.

@example

#### incorrect
 resource_name :foo
 provides :foo

 action :create do
   # some action code
 end

#### correct
 resource_name :foo
 provides :foo
 unified_mode true

 action :create do
   # some action code
 end

Constants

MSG

Public Instance Methods

insert_below_provides(corrector) click to toggle source
# File lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb, line 68
def insert_below_provides(corrector)
  provides_ast = provides(processed_source.ast).first
  if provides_ast
    corrector.insert_after(provides_ast, "\nunified_mode true")
    true
  end
end
insert_below_resource_name(corrector) click to toggle source
# File lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb, line 76
def insert_below_resource_name(corrector)
  resource_name_ast = resource_name(processed_source.ast).first
  if resource_name_ast
    corrector.insert_after(resource_name_ast, "\nunified_mode true")
    true
  end
end
on_new_investigation() click to toggle source
# File lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb, line 56
def on_new_investigation
  # gracefully fail if the resource is empty
  return if processed_source.ast.nil?

  # Using range similar to RuboCop::Cop::Naming::Filename (file_name.rb)
  return if unified_mode?(processed_source.ast)
  range = source_range(processed_source.buffer, 1, 0)
  add_offense(range, severity: :refactor) do |corrector|
    insert_below_provides(corrector) || insert_below_resource_name(corrector)
  end
end