class RuboCop::Cop::Chef::Correctness::MacosUserdefaultsInvalidType

The macos_userdefaults resource prior to Chef Infra Client 16.3 would silently continue if invalid types were passed resulting in unexpected behavior. Valid values are: “array”, “bool”, “dict”, “float”, “int”, and “string”.

@example

#### incorrect
macos_userdefaults 'set a value' do
  global true
  key 'key'
  type 'boolean'
end

#### correct
macos_userdefaults 'set a value' do
  global true
  key 'key'
  type 'bool'
end

Constants

INVALID_VALUE_MAP
MSG
VALID_VALUES

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb, line 53
def on_block(node)
  match_property_in_resource?(:macos_userdefaults, 'type', node) do |type|
    type_val = method_arg_ast_to_string(type)
    return if VALID_VALUES.include?(type_val)
    add_offense(type, message: MSG, severity: :refactor) do |corrector|
      next unless INVALID_VALUE_MAP[type_val]
      corrector.replace(type, "type '#{INVALID_VALUE_MAP[type_val]}'")
    end
  end
end