Class: RuboCop::Cop::Chef::Deprecations::VerifyPropertyUsesFileExpansion

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetChefVersion
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb

Overview

In Chef Infra Client 13 the “file” variable for use within the verify property was replaced with the “path” variable.

Examples:


### incorrect
file '/etc/nginx.conf' do
  verify 'nginx -t -c %{file}'
end

### correct
file '/etc/nginx.conf' do
  verify 'nginx -t -c %{path}'
end

Constant Summary collapse

MSG =
"Use the 'path' variable in the verify property and not the 'file' variable which was removed in Chef Infra Client 13."

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/rubocop/cop/chef/deprecation/verify_property_file_expansion.rb', line 45

def on_block(node)
  match_property_in_resource?(nil, 'verify', node) do |verify|
    return unless verify.source.match?(/%{file}/)
    add_offense(verify, severity: :warning) do |corrector|
      corrector.replace(verify.loc.expression, verify.loc.expression.source.gsub('%{file}', '%{path}'))
    end
  end
end