Class: RuboCop::Cop::Chef::Deprecations::NodeMethodsInsteadofAttributes

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

Overview

Use node attributes to access data provided by Ohai instead of using node methods to access that data.

Examples:


### incorrect
node.fqdn
node.platform
node.platform_family
node.platform_version
node.hostname

### correct
node['fqdn']
node['platform']
node['platform_family']
node['platform_version']
node['hostname']

Constant Summary collapse

MSG =
'Use node attributes to access Ohai data instead of node methods, which were deprecated in Chef Infra Client 13.'
RESTRICT_ON_SEND =
%i(
current_user
domain
fqdn
hostname
ip6address
ipaddress
macaddress
machinename
ohai_time
os
os_version
platform
platform_build
platform_family
platform_version
root_group
shard_seed
uptime
uptime_seconds).freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb', line 69

def on_send(node)
  node_ohai_methods?(node) do
    add_offense(node.loc.selector, severity: :warning) do |corrector|
      corrector.replace(node, "node['#{node.method_name}']")
    end
  end
end