Class: RuboCop::Cop::Chef::ChefDeprecations::NamePropertyWithDefaultValue

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

Overview

A custom resource property can’t be marked as a name_property and also have a default value. The name property is a special property that is derived from the name of the resource block in and thus always has a value passed to the resource. For example if you define ‘my_resource ’foo’‘ in recipe, then the name property of `my_resource` will automatically be set to `foo`. Setting a property to be both a name_property and have a default value will cause Chef Infra Client failures in 13.0 and later releases.

Examples:


# bad
property :config_file, String, default: 'foo', name_property: true

# good
property :config_file, String, name_property: true

Constant Summary collapse

MSG =
"A resource property can't be marked as a name_property and also have a default value. This will fail in Chef Infra Client 13 or later.".freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/chef/deprecation/name_property_and_default.rb', line 34

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