Class: RuboCop::Cop::Chef::Modernize::ActionMethodInResource
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/modernize/action_method_in_resource.rb
Overview
Use the custom resource language’s ‘action :my_action` blocks instead of creating actions with methods.
Constant Summary collapse
- MSG =
"Use the custom resource language's `action :my_action` blocks instead of creating actions with methods."
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_def(node) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubocop/cop/chef/modernize/action_method_in_resource.rb', line 43 def on_def(node) return unless node.method_name.to_s.start_with?('action_') # when we stop support for Ruby < 2.7 the .to_s can go away here return if node.arguments? # if they passed in arguments they may actually need this return if node.parent && includes_poise?(node.parent) add_offense(node, severity: :refactor) do |corrector| # @todo when we drop ruby 2.4 support we can convert this to use delete_suffix corrector.replace(node, node.source.gsub("def #{node.method_name}", "action :#{node.method_name.to_s.gsub(/^action_/, '')} do")) end end |