Class: RuboCop::Cop::Chef::ChefDeprecations::LaunchdDeprecatedHashProperty

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

Overview

The launchd resource’s hash property was renamed to plist_hash in Chef Infra Client 13+ to avoid conflicts with Ruby’s hash class.

Examples:


# bad
launchd 'foo' do
  hash foo: 'bar'
end

# good
launchd 'foo' do
  plist_hash foo: 'bar'
end

Constant Summary collapse

MSG =
"The launchd resource's hash property was renamed to plist_hash in Chef Infra Client 13+ to avoid conflicts with Ruby's hash class.".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



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

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

#on_block(node) ⇒ Object



40
41
42
43
44
# File 'lib/rubocop/cop/chef/deprecation/launchd_deprecated_hash_property.rb', line 40

def on_block(node)
  match_property_in_resource?(:launchd, 'hash', node) do |hash_prop|
    add_offense(hash_prop, location: :expression, message: MSG, severity: :refactor)
  end
end