class RuboCop::Cop::Chef::RedundantCode::CustomResourceWithAllowedActions

It is not necessary to set ‘actions` or `allowed_actions` in custom resources as Chef Infra Client determines these automatically from the set of all actions defined in the resource.

@example

#### incorrect
allowed_actions [:create, :remove]

# also bad
actions [:create, :remove]

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb, line 45
def on_send(node)
  # avoid triggering on things like new_resource.actions
  return unless node.receiver.nil?

  # if the resource requires poise then bail out since we're in a poise resource where @allowed_actions is legit
  return if poise_require(processed_source.ast).any? || !resource_actions?(processed_source.ast)

  add_offense(node, severity: :refactor) do |corrector|
    corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
  end
end