class RuboCop::Cop::Chef::Correctness::InvalidPlatformValueForPlatformFamilyHelper

Pass valid platform families to the value_for_platform_family helper. See [Infra Language: Platform Family](docs.chef.io/infra_language/checking_platforms/#platform_family-values) for a complete list of platform families.

@example

#### incorrect
value_for_platform_family(
  %w(rhel sles) => 'foo',
  %w(mac) => 'foo'
)

#### correct
value_for_platform_family(
  %w(rhel suse) => 'foo',
  %w(mac_os_x) => 'foo'
)

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/chef/correctness/invalid_value_for_platform_family_helper.rb, line 52
def on_send(node)
  value_for_platform_family?(node) do |plats|
    plats.each do |p_hash|
      if p_hash.key.array_type?
        p_hash.key.values.each do |plat|
          next unless INVALID_PLATFORM_FAMILIES.key?(plat.value)
          add_offense(plat, message: MSG, severity: :refactor)
        end
      elsif INVALID_PLATFORM_FAMILIES.key?(p_hash.key.value)
        add_offense(p_hash.key, message: MSG, severity: :refactor)
      end
    end
  end
end