Class: RuboCop::Cop::Chef::Modernize::RespondToCompileTime

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

Overview

There is no need to check if the chef_gem resource supports compile_time as Chef Infra Client 12.1 and later support the compile_time property.

Examples:


### incorrect
chef_gem 'ultradns-sdk' do
  compile_time true if Chef::Resource::ChefGem.method_defined?(:compile_time)
  action :nothing
end

chef_gem 'ultradns-sdk' do
  compile_time true if Chef::Resource::ChefGem.instance_methods(false).include?(:compile_time)
  action :nothing
end

chef_gem 'ultradns-sdk' do
  compile_time true if respond_to?(:compile_time)
  action :nothing
end

### correct
chef_gem 'ultradns-sdk' do
  compile_time true
  action :nothing
end

Constant Summary collapse

MSG =
'There is no need to check if the chef_gem resource supports compile_time as Chef Infra Client 12.1 and later support the compile_time property.'

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



81
82
83
84
85
86
87
88
89
# File 'lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb', line 81

def on_block(node)
  match_property_in_resource?(:chef_gem, 'compile_time', node) do |compile_time_property|
    compile_time_method_defined?(compile_time_property.parent) do |val|
      add_offense(compile_time_property.parent, severity: :refactor) do |corrector|
        corrector.replace(compile_time_property.parent, "compile_time #{val.source}")
      end
    end
  end
end