Class: RuboCop::Cop::Chef::Deprecations::RubyBlockCreateAction

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

Overview

Use the :run action in the ruby_block resource instead of the deprecated :create action

Examples:


### incorrect
ruby_block 'my special ruby block' do
  block do
    puts 'running'
  end
  action :create
end

### correct
ruby_block 'my special ruby block' do
  block do
    puts 'running'
  end
  action :run
end

Constant Summary collapse

MSG =
'Use the :run action in the ruby_block resource instead of the deprecated :create action'

Instance Method Summary collapse

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



48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb', line 48

def on_block(node)
  match_property_in_resource?(:ruby_block, 'action', node) do |ruby_action|
    ruby_action.arguments.each do |action|
      next unless action.source == ':create'
      add_offense(action, severity: :warning) do |corrector|
        corrector.replace(action, ':run')
      end
    end
  end
end