Class: RuboCop::Cop::Chef::ChefModernize::SysctlParamResource

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/modernize/systctl_param_resource.rb

Overview

The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client 14.0. The new resource name should be used.

# bad
sysctl_param 'fs.aio-max-nr' do
  value '1048576'
end

# good
sysctl 'fs.aio-max-nr' do
  value '1048576'
end

Constant Summary collapse

MSG =
'The sysctl_param resource was renamed to sysctl when it was added to Chef Infra Client 14.0. The new resource name should be used.'.freeze

Instance Method Summary collapse

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Instance Method Details

#autocorrect(node) ⇒ Object



43
44
45
46
47
# File 'lib/rubocop/cop/chef/modernize/systctl_param_resource.rb', line 43

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, node.source.gsub(/^sysctl_param/, 'sysctl'))
  end
end

#on_send(node) ⇒ Object



39
40
41
# File 'lib/rubocop/cop/chef/modernize/systctl_param_resource.rb', line 39

def on_send(node)
  add_offense(node, location: :expression, message: MSG, severity: :refactor) if node.method_name == :sysctl_param
end