Class: RuboCop::Cop::Chef::ChefModernize::CustomResourceWithAttributes

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/modernize/resource_with_attributes.rb

Overview

In HWRPs and LWRPs you defined attributes, but custom resources changed the name to be properties to avoid confusion with chef recipe attributes. When writing a custom resource they should be called properties even though the two are aliased.

Examples:


# bad
attribute :something, String

action :create do
  # some action code because we're in a custom resource
end

# good
property :something, String

action :create do
  # some action code because we're in a custom resource
end

Constant Summary collapse

MSG =
'Custom Resources should contain properties not attributes'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



59
60
61
62
63
# File 'lib/rubocop/cop/chef/modernize/resource_with_attributes.rb', line 59

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.selector, 'property')
  end
end

#on_send(node) ⇒ Object



53
54
55
56
57
# File 'lib/rubocop/cop/chef/modernize/resource_with_attributes.rb', line 53

def on_send(node)
  attribute?(node) do
    add_offense(node, location: :selector, message: MSG, severity: :refactor) if resource_actions?(processed_source.ast)
  end
end