Class: RuboCop::Cop::Chef::ChefCorrectness::UnnecessaryNameProperty
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Chef::ChefCorrectness::UnnecessaryNameProperty
- Defined in:
- lib/rubocop/cop/chef/correctness/unnecessary_name_property.rb
Overview
There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources out of the box.
Constant Summary collapse
- MSG =
'There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources out of the box.'.freeze
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
44 45 46 47 48 |
# File 'lib/rubocop/cop/chef/correctness/unnecessary_name_property.rb', line 44 def autocorrect(node) lambda do |corrector| corrector.remove(node.source_range) end end |
#on_send(node) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/chef/correctness/unnecessary_name_property.rb', line 36 def on_send(node) name_property?(node) do |hash_vals| if hash_vals.empty? || (hash_vals.first.keys.count == 1 && hash_vals.first.keys.first.source == 'name_property') add_offense(node, location: :expression, message: MSG, severity: :refactor) end end end |