Class: RuboCop::Cop::Chef::Modernize::SetOrReturnInResources

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/chef/modernize/resource_set_or_return.rb

Overview

set_or_return within a method should not be used to define property in a resource. Instead use the property method which properly validates and defines properties in a way that works with reporting and documentation functionality in Chef Infra Client

Examples:


### incorrect
 def severity(arg = nil)
   set_or_return(
     :severity, arg,
     :kind_of => String,
     :default => nil
   )
 end

### correct
property :severity, String

Constant Summary collapse

MSG =
'Do not use set_or_return within a method to define a property for a resource. Use the property method instead, which supports validation, reporting, and documentation functionality'
RESTRICT_ON_SEND =
[:set_or_return].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



42
43
44
# File 'lib/rubocop/cop/chef/modernize/resource_set_or_return.rb', line 42

def on_send(node)
  add_offense(node, severity: :refactor)
end