Class: RuboCop::Cop::Chef::Modernize::PropertyWithNameAttribute

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb

Overview

When using properties in a custom resource you should use name_property not the legacy name_attribute from the days of attributes

Examples:


### incorrect
property :bob, String, name_attribute: true

### correct
property :bob, String, name_property: true

Constant Summary collapse

MSG =
'Resource property sets name_attribute instead of name_property'
RESTRICT_ON_SEND =
[:property].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
# File 'lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb', line 45

def on_send(node)
  property_with_name_attribute?(node) do |name_attribute|
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(name_attribute, 'name_property: true')
    end
  end
end