Class: RuboCop::Cop::Chef::ChefCorrectness::ResourceSetsNameProperty

Inherits:
RuboCop::Cop
  • 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:


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

# good
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.'.freeze

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

Instance Method Details

#on_block(node) ⇒ Object



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

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