Class: RuboCop::Cop::Chef::Deprecations::UserDeprecatedSupportsProperty

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/deprecation/user_supports_property.rb

Overview

The supports property was removed in Chef Infra Client 13 in favor of individual ‘manage_home’ and ‘non_unique’ properties.

Examples:


### incorrect
user "betty" do
  supports({
    manage_home: true,
    non_unique: true
  })
end

user 'betty' do
  supports :manage_home => true
end

### correct
user "betty" do
  manage_home true
  non_unique true
end

Constant Summary collapse

MSG =
"The supports property was removed in Chef Infra Client 13 in favor of individual 'manage_home' and 'non_unique' properties."

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

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubocop/cop/chef/deprecation/user_supports_property.rb', line 50

def on_block(node)
  match_property_in_resource?(:user, 'supports', node) do |property|
    add_offense(property, severity: :warning) do |corrector|
      new_text = []

      property.arguments.first.each_pair do |k, v|
        # account for a strange edge case where the person incorrectly makes "manage_home a method
        # the code would be broken, but without this handling cookstyle would explode
        key_value = (k.send_type? && k.method?(:manage_home)) ? 'manage_home' : k.value

        new_text << "#{key_value} #{v.source}"
      end

      corrector.replace(property, new_text.join("\n  "))
    end
  end
end