Class: RuboCop::Cop::Chef::Deprecations::ResourceWithoutUnifiedTrue
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Chef::Deprecations::ResourceWithoutUnifiedTrue
show all
- Extended by:
- AutoCorrector, TargetChefVersion
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/chef/deprecation/resource_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.
Constant Summary
collapse
- MSG =
'Set `unified_mode true` in Chef Infra Client 15.3+ custom resources to ensure they work correctly in Chef Infra Client 18 (April 2022) when Unified Mode becomes the default.'
Instance Method Summary
collapse
minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?
Methods inherited from Base
#target_chef_version
Instance Method Details
#insert_below_provides(corrector) ⇒ Object
68
69
70
71
72
73
74
|
# 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) ⇒ Object
76
77
78
79
80
81
82
|
# 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 ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rubocop/cop/chef/deprecation/resource_without_unified_mode_true.rb', line 56
def on_new_investigation
return if processed_source.ast.nil?
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
|