Class: RuboCop::Cop::Chef::ChefCorrectness::PropertyWithNameAttribute

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/correctness/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:


# bad
property :bob, String, name_attribute: true

# good
property :bob, String, name_property: true

Constant Summary collapse

MSG =
'Resource property sets name_attribute not name_property'.freeze

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



39
40
41
42
43
# File 'lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb', line 39

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, node.source.gsub('name_attribute', 'name_property'))
  end
end

#on_send(node) ⇒ Object



35
36
37
# File 'lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb', line 35

def on_send(node)
  add_offense(node, location: :expression, message: MSG, severity: :refactor) if attribute_method_mix?(node)
end