Class: RuboCop::Cop::Chef::Correctness::ResourceSetsNameProperty

Inherits:
Base
  • Object
show all
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb

Overview

Use name properties instead of setting the name property in a resource. Setting the name property directly causes notification and reporting issues.

Examples:


### incorrect
service 'foo' do
 name 'bar'
end

### correct
service 'foo' do
 service_name 'bar'
end

Constant Summary collapse

MSG =
'Resource sets the name property in the resource instead of using a name_property.'

Instance Method Summary collapse

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



41
42
43
44
45
# File 'lib/rubocop/cop/chef/correctness/resource_sets_name_property.rb', line 41

def on_block(node)
  match_property_in_resource?(nil, 'name', node) do |name_node|
    add_offense(name_node, severity: :refactor)
  end
end