Class: RuboCop::Cop::Chef::Modernize::CustomResourceWithAttributes

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
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:


### incorrect
attribute :something, String

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

### correct
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'
RESTRICT_ON_SEND =
[:attribute].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/rubocop/cop/chef/modernize/resource_with_attributes.rb', line 54

def on_send(node)
  return unless resource_actions?(processed_source.ast)
  attribute?(node) do
    add_offense(node.loc.selector, severity: :refactor) do |corrector|
      corrector.replace(node.loc.selector, 'property')
    end
  end
end