Class: RuboCop::Cop::Chef::RedundantCode::CustomResourceWithAllowedActions

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/chef/redundant/custom_resource_with_allowed_actions.rb

Overview

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.

Examples:


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

# also bad
actions [:create, :remove]

Constant Summary collapse

MSG =
'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'
RESTRICT_ON_SEND =
[:allowed_actions, :actions].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# 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