class RuboCop::Cop::Chef::Correctness::InvalidPlatformFamilyInCase
Use valid platform family values in case statements. See [Infra Language: Platform Family](docs.chef.io/infra_language/checking_platforms/#platform_family-values) for a complete list of platform families.
@example
### incorrect case node['platform_family'] when 'redhat' puts "I'm on a RHEL-like system" end
Constants
- MSG
Public Instance Methods
Source
# File lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb, line 43 def on_case(node) node_platform_family?(node.condition) do node.each_when do |when_node| when_node.each_condition do |con| next unless con.str_type? # if the condition isn't a string we can't check so skip # some invalid platform families have no direct correction value and return nil instead new_value = INVALID_PLATFORM_FAMILIES[con.str_content] next unless new_value add_offense(con, severity: :refactor) do |corrector| # if the correct value already exists in the when statement then we just want to delete this node if con.parent.conditions.any? { |x| x.str_content == new_value } range = range_with_surrounding_comma(range_with_surrounding_space(range: con.loc.expression, side: :left), :both) corrector.remove(range) else corrector.replace(con, "'#{new_value}'") end end end end end end