Class: RuboCop::Cop::Chef::ChefDeprecations::NodeMethodsInsteadofAttributes

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb

Overview

Incorrectly using node methods for Ohai data when you really want node attributes

Examples:


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

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

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



52
53
54
55
56
# File 'lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb', line 52

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, "node['#{node.method_name}']")
  end
end

#on_send(node) ⇒ Object



46
47
48
49
50
# File 'lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb', line 46

def on_send(node)
  node_ohai_methods?(node) do
    add_offense(node, location: :selector, message: MSG, severity: :refactor)
  end
end