Class: RuboCop::Cop::Chef::Deprecations::NodeSetUnless

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/deprecation/node_set_unless.rb

Overview

The node.set_unless method has been removed in Chef Infra Client 13 and usage must be replaced with node.normal_unless.

This cop will autocorrect code to use node.normal_unless, which is functionally identical to node.set_unless, but we also discourage the use of that method as normal level attributes persist on the node even if the code setting the attribute is later removed.

Examples:


### incorrect
node.set_unless['foo'] = true

### correct
node.normal_unless['foo'] = true

Constant Summary collapse

MSG =
'Do not use node.set_unless. Replace with node.normal_unless to keep identical behavior.'
RESTRICT_ON_SEND =
[:set_unless].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rubocop/cop/chef/deprecation/node_set_unless.rb', line 43

def on_send(node)
  node_set_unless?(node) do
    add_offense(node.loc.selector, severity: :warning) do |corrector|
      corrector.replace(node.loc.selector, 'normal_unless')
    end
  end
end